joh*_*sem 6 core-location clgeocoder
无论我给地理编码器提供什么地址([geocoder geocodeAddressString:completionHandler :),它总是只在地标数组中放置一个对象.
我有什么方法可以获得多个结果(例如在地图应用中),用户可以从中选择一个?
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
}];
Run Code Online (Sandbox Code Playgroud)
我对数据包进行了一些嗅探,看来 CLGeocoder 没有连接到 Google 的地理编码服务,而是连接到了 Apple 的服务。我还注意到每次我都只从那里得到一个地标。
如果你想要更复杂的东西,你应该使用谷歌或其他地理编码。我使用SVGeocoder (https://github.com/samvermette/SVGeocoder),它具有与 CLGeocoder 非常相似的 API。
归档时间: |
|
查看次数: |
2794 次 |
最近记录: |