[英]Using CLGeocoder to find the nearest city
So I've been looking at this for a while, and I can't seem to find a solution anywhere. 因此,我已经研究了一段时间,而且似乎无法在任何地方找到解决方案。 I am trying to use
CLGeocoder
in an iOS app to find the nearest city to where the user long taps on the map. 我正在尝试在iOS应用中使用
CLGeocoder
来查找用户在地图上长按的最近的城市。 I have two main problems: 我有两个主要问题:
CLGeocoder
often returns a nearby city instead of the more obvious answer of New York. CLGeocoder
经常返回附近的城市,而不是纽约的更明显答案。 I can't work out how to set the "fuzziness" of the search to overcome this issue. City
field is null in the returned placemark object, most commonly in remote areas such as deserts or oceans. City
字段为空,最常见的是在沙漠或海洋等偏远地区。 In this case, I would ideally want to find the nearest object that actually has City
defined, but can't work out how to do this. City
的最近的对象,但无法解决该问题。 For Get all Detail of your Location by using CLGeocoder
通过使用
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]);
}
}];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.