Contents

autocomplete(query, callback, options)

Retrieves a list of autocomplete results for the specified search query.

Declaration

autocomplete(
        query: string,
        callback: SearchDelegate<SearchAutocompleteResponse>,
        options?: SearchAutocompleteOptions,
    ): number;

Parameters

  • query:

    A string that represents the user’s search in progress.

  • callback:

    A callback function or delegate object.

  • options:

    With the Searchautocompleteoptions hash, you have the option to constrain the search to a desired area using the Coordinate or Region properties. A coordinate or region you supply here overrides the same property you supply to the Search constructor. You also have the option to override the Language for the search constructor. For example, { "language: "fr-CA" } tells the server to send results localized to Canadian French. For a complete list of options you can use to constrain your search, see Searchautocompleteoptions.

Return Value

This method returns an integer ID that you can pass to the cancel(id) method to cancel a pending request.

Discussion

To provide the user with a menu of search suggestions, invoke the autocomplete(query, callback, options) method as users type. This method minimizes typing and brings users the results they’re looking for.

MapKit JS invokes the callback function on failure and success with two arguments, error and data:

  • error. An error object that contains an error code and descriptive message.

  • data. A SearchAutocompleteResponse object that the system parses from a server-returned JSON response.

The system doesn’t call the callback function or delegate if you cancel the request before MapKit JS receives a response.

See Also

Performing a search autocomplete