如何獲取當前位置的經緯度。如何在IOS SDK 8.0中獲取當前位置的經緯度
我試試這個。使用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];
}
在這裏,我啓用模擬器位置部署8.0 iPhone模擬器4s。 即使在設備上它不工作。
@ALL 請讓我知道,我在這裏做錯了什麼。
加入既代表方法didFailWithError和didUpdateToLocation但這方法不觸發在所有 – KkMIW 2014-10-02 16:16:25
請在您的.h文件中添加CLLocationManagerDelegate,像這樣@interface DemoViewController:UIViewController –
Samin
2014-10-03 03:13:48
我添加了CLLocationManagerDel egate,我仍然有問題。升級sdk IOS 7到IOS 8後出現問題。 – KkMIW 2014-10-03 10:26:48