【发布时间】:2021-05-15 14:27:08
【问题描述】:
我必须找到当前位置,我正在使用此代码
-(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);
}
但是纬度和经度要归零了?我在viewDidLoad中调用了这些方法
[self getCurrentLocation];
[self getLocation];
为什么会这样,请帮助我。谢谢
【问题讨论】:
-
如果你知道答案为什么要投反对票然后在这里发帖?
-
你做错了。您需要使用
CLLocationManagerDelegate方法来获取坐标。你需要阅读Apple Doc -
我必须使用哪种方法?
-
@iphonic 我正在尝试但不工作告诉我该怎么做/
-
怎么做:阅读文档。如果您需要有人告诉您,任何 Mac 也可以为您朗读文档。
标签: ios objective-c cllocationmanager