有没有办法确定用户当前所在的具体位置?我希望展示的不仅仅是当前所在的城市或国家,而是显示湖泊,公园以及其他在地图上搜索的东西(即西尔斯大厦,纽约市中心,黄石公园)。此外,如果这是不可能的,任何人都可以提供一个示例,显示更新的方式来获取您所在的城市?我在Xcode中使用Obj-c,但是我在这方面遇到了麻烦。任何帮助将不胜感激!
以下是我目前使用的代码:
实施
CLLocationManager *locationManager;
viewDidLoad中
locationManager = [[CLLocationManager alloc] init];
按钮
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
无效方法
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
NSLog(@"%@", currentLocation);
}
}
答案 0 :(得分:0)
将您从LocationManager收到的坐标传递给CLGeocoder
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:currentLocation completionHandler:
^(NSArray *placemarks, NSError *error) {
if ([placemarks count] > 0) {
CLPlacemark *placemark = placemarks[0];
NSLog(@"country is: %@", placemark.country );
}
}];