Вопрос

I wonder how a request looks like or which class is used to get results like searching with Apple Maps? I've tried:

[geocoder geocodeAddressString:text
                 completionHandler:^(NSArray *placemarks, NSError *error)

that only seems to give back one result.

   MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
[search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error)

that gives back like local stores etc.

How can I get back results like if you type a few letters and you get back the 10 best matching cities?

Это было полезно?

Решение

Its the way as described above. In the end I used Google Maps API search to get the top 10 results that I was looking for.

Другие советы

For the geo-coding part: MKLocalSearch returns a list of MKMapItems Every MKMapItem has a MKPlacemark access by calling mapItem.placemark

This is where it gets cool, in placemark you can access the addressDictionary. Inside the addressDictionary, you can find all sorts of geo details such as address, formattedAddress, region, country etc.

MKLocalSearch uses a .naturalLanguageQuery to search its database. The problem with this setup, is that it will return the top 10 based on your current (or specified) location, which makes a search such as 'city' very difficult. Hope this helps!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top