ジオコーダ ([geocoder geocodeAddressString:completionHandler:) にどのようなアドレスを指定しても、目印配列には常に 1 つのオブジェクトのみが配置されます。
ユーザーが選択できる複数の結果を取得する方法はありますか (マップ アプリのように)。
ジオコーダ ([geocoder geocodeAddressString:completionHandler:) にどのようなアドレスを指定しても、目印配列には常に 1 つのオブジェクトのみが配置されます。
ユーザーが選択できる複数の結果を取得する方法はありますか (マップ アプリのように)。
Apple's native geocoding service is provided by the MapKit framework. The important object in this framework is MKLocalSearch, which can geocode addresses and return multiple results.
MKLocalSearch returns back 10 results in mapItems of type MKMapItem. Each MKMapItem contains a MKPlacemark object, which is a subclass of CLPlacemark.
Here's an example using MapKit's 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
}];
パケットのスニッフィングを行ったところ、CLGeocoder は Google のジオコーディング サービスではなく、Apple のジオコーディング サービスに接続しているようです。また、そこから毎回目印が 1 つしか得られないことにも気付きました。
より洗練されたものが必要な場合は、Google またはその他のジオコーディングを使用する必要があります。CLGeocoderと非常によく似た API を持つSVGeocoder (https://github.com/samvermette/SVGeocoder)を使用します。