CoreLocation iOS9存储坐标

时间:2015-12-11 07:18:42

标签: ios mobile core-location

我最近问了这个问题,不知道在iOS 9中对CL所做的更改。我正在尝试存储用户的当前位置,并且我已经更改了我的代码以反映iOS 9中的新委托方法,但是didUpdateLocations仍然是永远达不到。

以下是我原始问题的链接:Latitude & Longitude Not Retrieved

我的更新代码:

viewWillAppear中

- (void)viewWillAppear:(BOOL)animated{

manager = [[CLLocationManager alloc] init];
manager.delegate = self;

if ([manager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [manager requestWhenInUseAuthorization];
}
[manager startUpdatingLocation];
}

didUpdateLocations

- (void)locationManager:(CLLocationManager *)manager
 didUpdateLocations:(NSArray<CLLocation *> *)locations{

NSLog(@"Location: %@", locations);
CLLocation *currentLocation = locations.lastObject;

if (currentLocation != nil) {
    float latitude = currentLocation.coordinate.latitude;

    float longitude = currentLocation.coordinate.longitude;


    NSLog(@"dLongitude : %f", longitude);
    NSLog(@"dLatitude : %f", latitude);
}

else{ NSLog(@"ERROR");
     }

}

1 个答案:

答案 0 :(得分:1)

检查

authorizationStatus and startUpdatingLocation 

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status

你也可以去设置 - &gt;隐私 - &gt;位置服务(开启) - &gt;选择你的应用并在使用时选择。