繁体   English   中英

使用CLGeocoder查找最近的城市

[英]Using CLGeocoder to find the nearest city

因此,我已经研究了一段时间,而且似乎无法在任何地方找到解决方案。 我正在尝试在iOS应用中使用CLGeocoder来查找用户在地图上长按的最近的城市。 我有两个主要问题:

  1. 即使用户非常放大,并且用户轻按了纽约(这就是他们想要的),但由于地图的缩小程度, CLGeocoder经常返回附近的城市,而不是纽约的更明显答案。 我无法解决如何设置搜索的“模糊性”以克服此问题。
  2. 在许多情况下,返回的地标对象中的“ City字段为空,最常见的是在沙漠或海洋等偏远地区。 在这种情况下,理想情况下,我希望找到实际定义了City的最近的对象,但无法解决该问题。

通过使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM