gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:52:06 28 4
gpt4 key购买 nike

所以我一直在研究这个问题,但我似乎无法在任何地方找到解决方案。我正在尝试使用 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/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com