所以我一直在看这个问题,我似乎无法在任何地方找到解决方案。我正在尝试在iOS应用中使用CLGeocoder
来查找用户在地图上长按的最近城市。我有两个主要问题:
CLGeocoder
经常返回附近的城市而不是纽约更明显的答案。我无法弄清楚如何设置搜索的“模糊性”以克服这个问题。City
字段在返回的地标对象中为空,最常见于沙漠或海洋等偏远地区。在这种情况下,理想情况下,我希望找到实际定义City
的最近对象,但无法确定如何执行此操作。答案 0 :(得分:0)
使用CLGeocoder
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[currentLocation stopUpdatingLocation];
CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:latitudeValue longitude:longitudeValue];
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:myLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if(!error)
{
for (CLPlacemark * placemark in placemarks)
{
NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
NSLog(@"placemark.country %@",placemark.country);
NSLog(@"placemark.postalCode %@",placemark.postalCode);
NSLog(@"placemark.administrativeArea %@",placemark.administrativeArea);
NSLog(@"placemark.locality %@",placemark.locality);
NSLog(@"placemark.subLocality %@",placemark.subLocality);
NSLog(@"placemark.subThoroughfare %@",placemark.subThoroughfare);
}
}
else
{
NSLog(@"failed getting city: %@", [error description]);
}
}];
}