2012-08-12 109 views
0

我试图从我的代码中每隔10秒更新用户位置。但是当我从wifi移动到3G时,我面临一个问题。每一个替代的请求都来自我的wifi所在的位置。可以做什么?用户位置每10秒更新一次无线网络

这是我的代码

NSNumber * n1; NSNumber * n2;

if([ud boolForKey:@"applicationActive"]) 
    { 

     n1 = [NSNumber numberWithDouble:[map.userLocation coordinate].latitude]; 
     n2 = [NSNumber numberWithDouble:[map.userLocation coordinate].longitude]; 
    } 
    else 
    { 
     CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 
     locationManager.delegate = self; 
     [locationManager startUpdatingLocation]; 
     n1 = [NSNumber numberWithDouble:locationManager.location.coordinate.latitude]; 
     n2 = [NSNumber numberWithDouble:locationManager.location.coordinate.longitude]; 
     [locationManager stopUpdatingLocation]; 
    } 


    [dict setObject:[ud objectForKey:@"CurrentDriverID"] forKey:@"DriverId"]; 
    [dict setObject:[n1 stringValue] forKey:@"Latitude"]; 
    [dict setObject:[n2 stringValue] forKey:@"Longitude"]; 

    [requestG SaveDriverlocationWS:dict delegate:self]; 

注意:当发生这种情况时,应用程序停留在前台。 SaveDriverlocationWS方法将当前位置保存到服务器上

+0

http://www.macrumors.com/2012/08/09/ios-6-beta-adds-wi-fi-plus-cellular-option-to-increase-data-reliability/。 iOS 6,你必须爱上它的新功能。 – 2012-08-14 02:45:39

回答

0

您似乎没有为您的位置管理器设置准确性级别 - 我会尝试此操作并查看是否有所改进。从你的代码看起来,你可能会写一个驱动程序的应用程序,在这种情况下,你可能想要使用kCLLocationAccuracyBestForNavigation准确度级别(如果你,你应该使用另一个更合适的级别,因为BestForNavigation过滤器用尽了很多电源,专为手机处于汽车坞站和供电的情况而设计)。

+0

即使我距离我开始的wifi网络几英里,也会发生这种情况。不确定准确性是否是问题? – 2012-08-12 12:45:24

0

对我的理解。使用Wifi或3G是系统级设置。 CLLocationManager使用当前系统的网络来获取设备的位置,而程序员无法在3G/Wifi之间切换网络。

+0

是的,我的问题是,当我离开我的wifi和手机开关自动切换到3G时,它开始在当前位置和我从哪里开始的无线网络位置之间交替。任何想法应该做什么?谢谢 – 2012-08-12 12:47:00

+0

你的意思是最后一个wifi位置和新的3G位置之间有明显的区别? – 2012-08-12 12:48:51

+0

是的..我开始从一个WiFi位置的应用程序..但是当我离开wifi的手机开关3GG和问题开始.. – 2012-08-12 14:07:07