7

无论我给地理编码器的地址是什么([geocoder geocodeAddressString:completionHandler:),它总是只将一个对象放在地标数组中。

我有什么方法可以获得多个结果(例如在地图应用程序中),用户可以从中选择一个?

4

2 回答 2

11

Apple 的本地地理编码服务由MapKit 框架提供。该框架中的重要对象是MKLocalSearch,它可以对地址进行地理编码并返回多个结果。

MKLocalSearch 返回 10 个mapItems类型的结果MKMapItem。每个 MKMapItem 都包含一个MKPlacemark对象,它是CLPlacemark.

这是一个使用 MapKit 的示例MKLocalSearch

MKLocalSearchRequest* request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = @"Calgary Tower";
request.region = MKCoordinateRegionMakeWithDistance(loc, kSearchMapBoundingBoxDistanceInMetres, kSearchMapBoundingBoxDistanceInMetres);

MKLocalSearch* search = [[MKLocalSearch alloc] initWithRequest:request];
[search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
   yourArray = response.mapItems; // array of MKMapItems
   // .. do you other logic here  
 }];
于 2013-04-22T21:16:04.657 回答
3

我对数据包做了一些嗅探,似乎 CLGeocoder 没有连接到 Google 的地理编码服务,而是连接到 Apple 的。我还注意到我每次只从那里得到一个地标。

如果你想要更复杂的东西,你应该使用谷歌或其他地理编码。我使用SVGeocoder (https://github.com/samvermette/SVGeocoder),它具有与 CLGeocoder 非常相似的 API。

于 2012-06-02T17:34:59.187 回答