【发布时间】:2013-12-06 05:31:45
【问题描述】:
我正在尝试通过 LocationManager 获取坐标。当我在 WIFI 网络上时,我得到了完美的位置。但是当我切换到蜂窝数据时得到不正确的位置(距离我当前位置 500m 的半径)。我尝试了“desiredAccuracy”的所有组合,但未能获得准确的坐标。有什么解决办法吗?
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
currentLocation = nil;
[locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{if(currentLocation != nil)
currentLocation = NULL;
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
NSLog(@"Location age %f", locationAge);
if (locationAge > 0.1) return;
currentLocation = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
NSLog(@"current location - %@",currentLocation);
NSString *lat =[NSString stringWithFormat:@"%lf",currentLocation.coordinate.latitude];
NSString *lon =[NSString stringWithFormat:@"%lf",currentLocation.coordinate.longitude];
latitudeText.text = lat;
longitudeText.text = lon;
[manager stopUpdatingLocation];}
【问题讨论】:
-
您是在静态位置检查这个吗?
-
不。我正在设备上试用。
-
这可能有 2 个原因.. 1) 您的 SIM 卡上未启用网络.. 2) 手机信号塔有问题.. 在办公室以外的其他位置检查您的应用程序..还可以尝试禁用 wifi,然后使用蜂窝数据进行检查。
-
互联网连接没有问题。一切安好。我正在获取坐标,但半径约为 500m
-
是的,Dinesh,你说的上述所有组合都试过了。但仍无法获取准确位置。
标签: ios iphone gps core-location cllocationmanager