How to get multiple tags from CLGeocoder

No matter what address I pass to the geocoder ([geocoder geocodeAddressString: completeHandler :), it always puts only one object in the tags array.

Is there a way to get several results (for example, in the Maps application) from which the user can choose one?

+5
source share
2 answers

I sniffed the packages a bit and it looks like CLGeocoder is not connecting to the Google geocoding service, but to Apple. I also noticed that every time I get only one label.

If you need something more complex, you should use Google or other geocoding. I use SVGeocoder (https://github.com/samvermette/SVGeocoder) which has a very similar API for CLGeocoder.

+1
source

Apple geocoding service based on MapKit framework . An important object in this structure is MKLocalSearch , which can geocode addresses and return multiple results.

MKLocalSearch returns 10 results in mapItems type MKMapItem . Each MKMapItem contains an MKPlacemark object, which is a subclass of CLPlacemark .

Here is an example using 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 }]; 
+9
source

All Articles