iphone - 使用 CLGeocoder 查找最近的城市

标签 iphone ios mapkit clgeocoder

所以我一直在研究这个问题,但我似乎无法在任何地方找到解决方案。我正在尝试使用 CLGeocoder在 iOS 应用程序中查找用户在 map 上长按的最近的城市。我有两个主要问题:

  • 即使用户非常缩小,并且用户点击说纽约(这是他们想要的),因为 map 的缩小程度,CLGeocoder经常返回附近的城市,而不是更明显的答案纽约。我不知道如何设置搜索的“模糊性”来克服这个问题。
  • 在许多情况下,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]);
            }
    
        }];
    
    
    }
    

    关于iphone - 使用 CLGeocoder 查找最近的城市,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14834429/

    相关文章:

    iphone - 为什么标签在 TableView 中更改为重用单元格

    ios - 如何在 Ios 中添加 customView xib 作为注释?

    ios5 - MKMapView NSInvalidArgumentException ios 中的无效区域崩溃

    iphone - iOS Quartz UIView 集成

    ios - 可滚动 UITableView 作为覆盖层

    iphone - iOS ping 和 ttl 超时

    ios - 设备方向颠倒不起作用

    objective-c - 我在 iPhone 应用程序中收到错误 0x8badf00d,这不是通常的嫌疑人

    iphone - 在另一个 View Controller 中调用方法导致循环

    ios - 如何设置GPUImagePicture的边框