Address lookup/autocomplete/reverse-geolookup for Google, OpenStreet, Bing, and OpenCage.
- Small size(2.3K min/gzipped)
- Working on NodeJS and Browser
npm install geo-coder --save-dev
global.fetch = require('node-fetch'); // set fetch for nodeJS
var GeoCode = require('geo-coder').GeoCode;
var geoCode = new GeoCode();
// geolookup example
geocode.geolookup('Brampton, Canada').then(result => {
console.log(result)) // [ { source: 'OpenStreetMap', lng: -79.752502, lat: 43.715783,..}]
});
// reverse lookup example
geocode.reverse(43.653226, -79.3831843).then(result => {
console.log(result) // {source: 'OpenStreetMap', address: 'Brampton, ON'...}
});
Add the library
<script src="https://unpkg.com/geo-coder"></script>
var geoCode = new GeoCode();
// geolookup example
geoCode.geolookup('Brampton, Canada').then(result => {
console.log(result);
});
// reverse lookup example
geoCode.reverse(43.653226, -79.3831843).then(result => {
console.log(result);
});
var googleGeoCode = new GeoCode('google', { key: 'g0o...' });
var bingGeoCode = new GeoCode('bing', { key: 'b1n...' });
var opencageGeoCode = new GeoCode('opencage', { key: 'op3...' });
An API key is required for the following providers.
Google: https://developers.google.com/maps/documentation/javascript/get-api-key
Bing: https://msdn.microsoft.com/en-us/library/ff428642.aspx
OpenCage: https://geocoder.opencagedata.com