MapQuest.js

L.mapquest.geocoding(options)

A class that acts as a simple interface to the MapQuest Geocoding API. Forward, Reverse, and Batch Geocoding are supported through the class.

Syntax

L.mapquest.key = 'KEY';

var geocoder = L.mapquest.geocoding({
  thumbMaps: false,
  maxResults: 3
});

Parameters

  • options object

    An object containing options from the Geocoding API.

Return Value

A geocoding object configured with the provided options.

geocoder.geocode(locations, callback)

Performs a forward geocode on the provided locations.

Syntax

L.mapquest.key = 'KEY';

var geocoder = L.mapquest.geocoding();
geocoder.geocode(['Denver, CO', 'Boulder, CO'], geocodingCallback);

function geocodingCallback(error, result) {
  console.log(result);
}

Parameters

  • locations required Array or String

    The locations parameter may be either a single location as a String, or an Array of multiple String locations. If an Array of locations is provided, the Batch Geocode API will be used.

  • callback Function

    Optional callback function. If provided, the results of the API call will be passed into the function in the error-first callback style. If not provided, geocoded locations will be displayed on the map with markers set to their locations.

Return Value

If a callback is provided, the Geocoding API response will be returned.

geocoder.reverse(latLng, callback)

Performs a reverse geocode on the provided lat/lng.

Syntax

L.mapquest.key = 'KEY';

var geocoder = L.mapquest.geocoding();
geocoder.reverse([37.78008,-122.420168], geocodingCallback);

function geocodingCallback(error, result) {
  console.log(result);
}

Parameters

  • latLng Array or object

    Either an object with lat and lng keys, or a lat/lng array.

  • callback Function

    Optional callback function. If provided, the results of the API call will be passed into the function in the error-first callback style. If not provided, geocoded locations will be displayed on the map with markers set to their locations.

Return Value

If a callback is provided, the Geocoding API response will be returned.