Class

MKLocalSearchCompleter

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

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. 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.

Topics

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 filterType: MKSearchCompletionFilterType

The filter options for the search results.

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.

Constants

enum MKSearchCompletionFilterType

Constants indicating the types of search completions to return.

Relationships

Inherits From

Conforms To

See Also

Placemark Search

class MKLocalSearch

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

class MKLocalSearchRequest

The parameters to use when searching for points of interest on the map.

class MKLocalSearchResponse

The results from a map-based search.

class MKLocalSearchCompletion

A fully formed string that completes a partial string.