MapQuest.js

L.mapquest.geocodingControl(options)

A control that adds interactive geocoding functionality to the map. Geocoded locations will have markers set to their locations. If enabled, the Search Ahead API will provide predictive results based on the provided input.

Syntax

L.mapquest.key = 'KEY';

var map = L.mapquest.map('map', {
  center: [39.7392,-104.9903],
  layers: L.mapquest.tileLayer('map'),
  zoom: 12
});

map.addControl(L.mapquest.control());
map.addControl(L.mapquest.geocodingControl({
  position: 'topleft'
}));

Parameters

  • options object

    An object containing any of the following key value options: position, keepOpen, searchAhead, compactResults, closeResultsOnClick, geocodingOptions, and searchAheadOptions.

    • position String optional, defaults to 'topleft'

      The position of the control (one of the map corners).

      Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'.

    • keepOpen Boolean optional, defaults to false.

      Determines if input field of the control should remain open after a geocode.

    • searchAhead Boolean optional, defaults to true.

      Determines if the Search Ahead functionality should be enabled on the control.

      If L.mapquest.open is set to true, this feature will automatically be disabled.

    • searchAheadOptions Object optional

      Options to be passed into the Search Ahead API if it is enabled.

      Any Request Parameters of the Search Ahead API are valid options.

      If the location parameter is not set in this object, Search Ahead results will be based on the current map center.

    • geocodingOptions Object optional

      Options to be passed into the Geocoding API.

      Any Request Parameters of the Geocoding API are valid options.

    • compactResults Boolean optional, defaults to false.

      Determines if a compact version of Search Ahead results should be used.

    • closeResultsOnClick Boolean optional, defaults to true.

      Determines if Search Ahead results should automatically close when a result is selected.

    Example

    {
      position: 'topright',
      keepOpen: false,
      searchAhead: true,
      compactResults: true,
      closeResultsOnClick: true,
      searchAheadOptions: {
        limit: 6
      }
    }

Return Value

An L.Control object that can be added to a map with the addControl() function.

Visual Example