A reverse geocoder takes a latitude and longitude coordinate and gives you the (best-guess) address of that location. This library provides easy access to multiple reverse geocoders under a unified interface. Currently supported are:
google
- Google Mapsmapquestopen
- MapQuest Open (requires API key)mapquestnominatim
- MapQuest Nominatim (default)
The library is somewhat USA-centric right now, due to our current use cases.
Interface
The reverseGeocode
function takes a latitude and longitude, along with an
optional service name to override which service is chosen. It returns a Q
promise for the results object.
var rg = ;rg;
will print:
street_number: '1640' street: 'Chicago Avenue' city: 'Evanston' state: 'Illinois' postal_code: '60201' country: 'United States of America' formatted_address: 'Whole Foods, 1640, Chicago Avenue, South Evanston, Evanston, Cook County, Illinois, 60201, United States of America'
You can override the service that is called by passing in a third argument to
reverseGeocode
:
rg;
Results are translated into a common format, which is an object containing the following properties:
- street_number
- street
- city
- state
- postal_code
- country
- formatted_address
The result may be missing one or more of these properties if no data was found, most commonly the street number.