如何获取当前位置的经纬度。
我试过这个。使用 Xcode 6.01 和 IOS SDK 8.0
-(CLLocationCoordinate2D) getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
- (void)getCurrentLocation{
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"Latitude = %@", latitude);
NSLog(@"Longitude = %@", longitude);
}
- (void)viewDidLoad{
[super viewDidLoad];
[self getCurrentLocation];
}
在这里,我将模拟器位置启用为 Deployment 8.0 iPhone 模拟器 4s。即使在设备上也无法正常工作。
@ALL 请让我知道,我在这里做错了什么。