Contents

MKLocalSearchCompleter

A utility object for generating a list of completion strings based on a partial search string that you provide.

Declaration

class MKLocalSearchCompleter

Overview

You use an MKLocalSearchCompleter object to retrieve auto-complete suggestions for your own map-based search controls. As the user types text, you feed the current text string into the search completer object, which delivers possible string completions that match locations or points of interest.

You create and configure MKLocalSearchCompleter objects yourself. You must always assign a delegate object to the search completer so that you can receive the search results that it generates. Specify a search region to restrict results to a designated area. The following code shows a simple example of a view controller that stores the MKLocalSearchCompleter object in a property. The view controller itself acts as the delegate for the completer and the view controller uses the region associated with an MKMapView object that’s part of the view controller’s interface. Completer objects are long-lived objects, so you can store strong references to them and reuse them later in your code.

Listing 1. Creating and configuring a search completer

Update the value of the completer’s queryFragment property to begin a search query. You can update this property in real time as the user types new characters into a text field because the completer object waits a short amount of time for the query string to stabilize. When modifications to the query string stop, the completer initiates a new search and returns the results to your delegate as an array of MKLocalSearchCompletion objects.

Topics

Receiving the search results

Specifying the query attributes

Canceling the query

Getting the current query results

See Also

Local search