【问题标题】:Apple CLGeocoder,MKLocalSearch result differ from device map resultApple CLGeocoder,MKLocalSearch 结果与设备地图结果不同
【发布时间】:2017-04-13 02:55:27
【问题描述】:

在我使用位置字符串搜索应用程序时,它会返回 5 结果,但与默认设备地图应用程序不匹配。

我的代码 1:CLGeocoder

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:searchKey completionHandler:^(NSArray* placemarks, NSError* error){
    dispatch_async(dispatch_get_main_queue(), ^{
        if (placemarks.count > 0) {
            searchLocations = placemarks;
        } else {
            searchLocations = nil;
        }
        [searchTableView reloadData];

        for (CLPlacemark *placemark in placemarks) {
            NSLog(@"place dic %@",placemark.addressDictionary);
        }
    });
}];

代码 2:MKLocalSearch

CLLocation *userLoc = (CLLocation *)[[MYLocationManager defaultManager] currentLocation];
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.region = MKCoordinateRegionMakeWithDistance(userLoc.coordinate, 100000, 100000);
request.naturalLanguageQuery = searchKey;
MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
[search startWithCompletionHandler:^(MKLocalSearchResponse * _Nullable response, NSError * _Nullable error) {
    NSMutableArray *locs = [[NSMutableArray alloc]init];
    for (MKMapItem *placeM in response.mapItems) {
        [locs addObject:placeM.placemark];
    }
    if (locs.count > 0) {
        searchLocations = locs;
    } else {
        searchLocations = nil;
    }


    dispatch_async(dispatch_get_main_queue(), ^{
    [searchTableView reloadData];
    });
}];

两者都返回相同的结果

设备地图应用结果:

设备地图结果与编码地理结果不同。请帮助解决这个问题。 我的问题是什么类型的搜索方法使用默认地图应用程序? 以及如何在编码中获得相同的结果?

【问题讨论】:

    标签: ios objective-c mapkit clgeocoder mklocalsearch


    【解决方案1】:

    请参考this答案。它描述了复制上述结果所需的所有步骤。我已经在模拟器上测试过了。

    【讨论】:

      【解决方案2】:

      查询结果取决于您搜索的区域。

      这是MKLocalSearch 中的“本地”。

      您的代码示例中的位置是用户在边长为 10 公里的区域中的位置。

      内置地图搜索的区域应等于或取决于您此时在应用中显示的区域。

      Apples App 中的区域可能与您应用中的显式区域非常不同。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多