MKLocalSearch
MKLocalSearchRequest takes a naturalLanguageQuery, such as “Taxidermists”, and an optional bounding geographic region to constrain results. In practice, the region is usually passed from an MKMapView.
MKLocalSearchResponse is returned in the eponymous block handler of MKLocalSearch -startWithCompletionHandler:, and returns an array of MKMapItem objects. Each MKMapItem contains information like name, phoneNumber, url and address information via the placemark property.
→ nshipster.com/mklocalsearch/
Apple Maps had a rough launch in iOS 6, but many missed a useful new feature added in iOS 6.1: MKLocalSearch.
MKLocalSearch lets your app search for places (restaurants, shops, etc.) using normal language, all powered by Apple’s own data.
How it works:
- Create an MKLocalSearchRequest
- Set naturalLanguageQuery (for example “coffee” or “pizza”)
- Optionally set a region (usually the visible part of your MKMapView)
- Start the search
It returns a list of MKMapItem objects with name, address, phone number, website, and coordinates.
Key advantages:
- Completely free with no usage limits or API keys
- Works perfectly with MKMapView and MKAnnotation
- Can be cancelled if needed
Because Apple does not charge for it and imposes no quotas, MKLocalSearch is often the simplest and cheapest way to add place search to an iOS app – even if you use another map for display. It remains a hidden gem of MapKit.
Category:
Tags:
Year: