我试图获得用户的纬度和经度,但我得到了结果0.000000 - 我尝试了以下代码.
码:
locationmanager=[[CLLocationManager alloc]init];
locationmanager.delegate=self;
// check before requesting, otherwise it might crash in older version
if ([locationmanager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationmanager requestWhenInUseAuthorization];
}
[locationmanager startUpdatingLocation];
#pragma mark - CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"locations %@",locations);
CLLocation*location = [locations lastObject];
NSLog(@"location %f",location.coordinate.latitude);
}
Run Code Online (Sandbox Code Playgroud)
结果:2014-10-15 11:10:20.118好[714:25676]纬度0.000000