Skip to content

MapQuest.js

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

Syntax

js
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

js
L.mapquest.key = 'KEY';

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

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

Parameters

Request ParameterDescriptionRequired
locations
Array or String
The locations parameter may be either a single line address as a string, an advanced location object, an array of multiple single line address strings, or an array of advanced location objects.
If an array of locations is provided, the Batch Geocode API will be used.
Example: Advanced Location Object
{ city: 'Denver', state: 'CO' }

Example: Array of Advanced Location Objects
[{ city: 'Boulder', state: 'CO'}, { city: 'Denver', state: 'CO' }]

Example: Single Line Address String
'Denver, CO'

Example: Array of Single Line Addresses
['Denver, CO', 'Boulder, CO']

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

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

js
L.mapquest.key = 'KEY';

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

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

Parameters

Request ParameterDescriptionRequired
latLng
Array or object
Either an advanced location object, an object with lat and lng keys, or a lat,lng array.
Example: Advanced Location Object
{ latLng: {lat: '40.7128', lng: '-74.0059'} }

Example: latLng Object
L.latLng([-81.470448, 30.333472])

Example: lat,lng array
[-81.470448, 30.333472]
No
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.No

Return Value

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