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


class MKLocalSearchCompleter : NSObject


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. You should also specify a search region to restrict results to a designated area.Listing 1 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 is 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

- (void)viewDidLoad {
   [super viewDidLoad];
   self.completer = [[MKLocalSearchCompleter alloc] init];
   self.completer.delegate = self;
   // Limit search results to the map view's current region.
   self.completer.region = self.myMapView.region;

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 strong stop, the completer initiates a new search and returns the results to your delegate as an array of MKLocalSearchCompletion objects.


Receiving the Search Results

var delegate: MKLocalSearchCompleterDelegate?

The object that receives the completion results.

protocol MKLocalSearchCompleterDelegate

Defines the methods for receiving search completion data.

Specifying the Query Attributes

var queryFragment: String

The search string for which you want completions.

var region: MKCoordinateRegion

The region that defines the geographic scope of the search.

var resultTypes: MKLocalSearchCompleter.ResultType

The types of search completions to include.

var pointOfInterestFilter: MKPointOfInterestFilter?

A filter that lists point of interest categories to include or exclude in the search.

var filterType: MKLocalSearchCompleter.FilterType

The filter options for the search results.

struct MKLocalSearchCompleter.ResultType

Options that indicate types of search completions.

Cancelling the Query

func cancel()

Cancels an in-progress search operation.

var isSearching: Bool

A Boolean value indicating whether a search operation is in progress.

Getting the Current Query Results

var results: [MKLocalSearchCompletion]

The most recently received search completions.


enum MKLocalSearchCompleter.FilterType

Constants indicating the types of search completions to return.



Inherits From

Conforms To

See Also

Placemark and Local Search

Searching for Nearby Points of Interest

Provide automatic search completions based on a user’s partial search query, and search the map for relevant locations nearby.

class MKPlacemark

A user-friendly description of a location on the map.

class MKLocalSearch

A utility object for initiating map-based searches and processing the results.

struct MKLocalSearch.ResultType

Options that indicate types of search results.

struct MKLocalSearchCompleter.ResultType

Options that indicate types of search completions.

class MKLocalSearchCompletion

A fully formed string that completes a partial string.