4

这是我在堆栈上的第一篇文章。我是 iOS 开发新手,需要地理编码方面的帮助。

特别是,根据 Apple 的文档:“返回的地标对象的数量在很大程度上取决于所提供信息的特异性。因此,提供街道、城市、省和国家/地区信息更有可能返回单个地址,而不仅仅是街道和城市信息。”

因此,在提供地址字符串时宽泛,应该(理论上)返回多个结果。

例子:

-(void)geocodeAddress {
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder geocodeAddressString:@"DMV, San Francisco, CA" completionHandler:^(NSArray *placemarks, NSError *error) {
    if (!error) {
        NSLog(@"Found: %i", [placemarks count]);
        for (CLPlacemark *placemark in placemarks) {
            CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(placemark.location.coordinate.latitude, placemark.location.coordinate.longitude);
            MapAnnotation *annotation = [MapAnnotation mapAnnotationWithCoordinate:coordinate title:@"DMV" subtitle:@"Great service?"];
            [self.mapView addAnnotation:annotation];
        }
    } else {
        NSLog(@"Error code: %i", [error code]);
    }
}];

}

让我有点困惑的是,无论我的“搜索”有多广泛(星巴克,DMV,与 1234 S 312th Place,City,State),我总是会返回一个位置。

所以,我的问题是,有没有办法为特定搜索返回多个结果?

4

1 回答 1

0

看起来 CLGeocoder 在这个阶段非常有限。在更新解决此问题之前,您最好的选择是使用其他服务(例如 Google Maps Geocoding API)。请注意,您只能将 Google 地理编码与谷歌地图一起使用:https ://developers.google.com/maps/documentation/geocoding/

于 2013-04-09T10:25:31.227 回答