我根据 iOS8.1 SDK 对我的应用程序进行了必要的更改以跟踪位置。我正在使用下面的代码来获取纬度和经度。即使我没有得到纬度和经度值。我是否需要做除此之外的任何更改以获得纬度和经度值?
在 appdelegate.h 中:
CLLocationManager *locationManager;
在 appdelegate.m 中:
- (void)applicationDidBecomeActive:(UIApplication *)application{
if (locationManager==nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
}
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
NSLog(@" location details %f %f ",locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude);
}
在 Info.plist 文件中
<key>NSLocationAlwaysUsageDescription</key>
<string>This will be used to obtain or track your location.</string>