【发布时间】:2014-06-14 18:51:18
【问题描述】:
我正在使用核心位置来存储纬度/经度坐标。我在 viewDidLoad 中有以下代码。
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[self.locationManager startUpdatingLocation];
这是我的委托方法。
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
[self.locationManager stopUpdatingLocation];
CLLocation* loc = [locations lastObject]; // locations is guaranteed to have at least one object
float latitude = loc.coordinate.latitude;
float longitude = loc.coordinate.longitude;
self.lat = [NSString stringWithFormat:@"%.8f",latitude];
self.longString = [NSString stringWithFormat:@"%.8f",longitude];
}
我正在使用 GPS 来跟踪这些坐标,但似乎不一致。启动应用程序后,位置服务图标不会经常出现。但是,如果我切换我的 wifi,它会起作用。或者,如果我打开地图应用程序并提示它获取我的当前位置,然后切换到我的应用程序,它就会工作。有时,它会毫无顾忌地工作。如果未显示位置服务图标,则我的纬度/经度值为空。有任何想法吗?提前致谢!
【问题讨论】:
标签: ios objective-c gps core-location