iOS Developer Library

Developer

MapKit Framework Reference MKLocalSearchRequest Class Reference

Options
Deployment Target:

On This Page
Language:

MKLocalSearchRequest

An MKLocalSearchRequest object is a utility object that you use to specify map-based search parameters. You can create an instance of this object and specify a natural language search string yourself, or you can use an MKLocalSearchCompleter object to obtain a more specific search term based on user input. You should also specify a specific map region to narrow the search results. You then use the configured object to initialize an MKLocalSearch object and perform your search.

When creating an MKLocalSearchRequest object yourself, set the naturalLanguageQuery property to an appropriate search string, as in the following example:

Objective-C

  1. MKLocalSearchRequest* request = [[MKLocalSearchRequest alloc] init];
  2. request.naturalLanguageQuery = @"coffee";
  3. // Set the region to an associated map view's region
  4. request.region = myMapView.region;

Swift

  1. let request = MKLocalSearchRequest()
  2. request.naturalLanguageQuery = "coffee"
  3. // Set the region to an associated map view's region
  4. request.region = myMapView.region

If your app uses an MKLocalSearchCompleter object to implement auto-complete support for user-supplied search strings, you can initialize your search request using the search completion selected by the user. In that case, use the initWithCompletion: method to initialize your search request object instead of the init method. The completion object provides the value for the naturalLanguageQuery property.

  • Initializes and returns a search request based on the specified search completion data.

    Declaration

    Swift

    init(completion completion: MKLocalSearchCompletion)

    Objective-C

    - (instancetype)initWithCompletion:(MKLocalSearchCompletion *)completion

    Parameters

    completion

    A search completion object obtained from an MKLocalSearchCompleter object. The search request uses the provided object to set the value of the naturalLanguageQuery property.

    Return Value

    An initialized search request.

    Discussion

    Use this method when initializing your object from MKLocalSearchCompleter objects. You do not need to use this method if you intend to provide the search string and region information yourself.

    Availability

    Available in iOS 9.3 and later.

  • A string containing the desired search item.

    Declaration

    Swift

    var naturalLanguageQuery: String?

    Objective-C

    @property(nonatomic, copy) NSString *naturalLanguageQuery

    Discussion

    You specify this parameter as a string describing the map-based item you want to look for. The text is equivalent to what the user would type in a search field in the Maps app. For example, the text might contain all or part of an address or it might contain the name of a point of interest.

    This property must not be nil.

    Availability

    Available in iOS 6.1 and later.

  • A map region that provides a hint as to where to search.

    Declaration

    Swift

    var region: MKCoordinateRegion

    Objective-C

    @property(nonatomic, assign) MKCoordinateRegion region

    Discussion

    You can use this parameter to narrow the list of search results to those inside or close to the specified region. Specifying a region does not guarantee that the results will all be inside the region. It is merely a hint to the search engine.

    Availability

    Available in iOS 6.1 and later.