I want to use MKLocalSearch
for searching in a Map. This functionality is available in iOS 6.1+. Does anybody know how to use this or can anybody give an example of how to use an MKLocalSearch
?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
The API for
MKLocalSearch
is fairly easy to understand. At its most basic, youalloc-init
anMKLocalSearchRequest
naturalLanguageQuery
to some search termMKLocalSearch
objectMKMapItem
objects in the responseSearch for Cafes:
You can specify a region for the search like this:
You can also take the region from an
MKMapView
that the user has zoomed into. This will give better results:The response object, an
MKLocalSearchResponse
, contains an array ofMKMapItem
objects (mapItems
) and anMKCoordinateRegion
calledboundingRegion
, which is a region that contains all the results. You can use it to set a map view to show all results:The array of
MKMapItem
objects can't be placed on a map (they're used for sending to the Maps app) but each contains aplacemark
property which can be added to a map:Search for Dublin places a pin on the map view and logs:
There are a load of extra details in the returned objects, especially if you search for businesses. Here are a few:
Here is a tutorial for Localsearch
http://jeffreysambells.com/2013/01/28/mklocalsearch-example
Here is an example that search for cafes in a radius of 1 km around a given location :
Please note than when the search is unsuccessful, it does not return an empty list, but an error with domain
MKErrorDomain
and code4
.