Convert addresses to latitude and longitude, and vice versa, to easily display maps such as lower-cost Google Maps alternatives. This fork of GeocoderJS is a JavaScript port of the Geocoder PHP library that's been updated a bit. It's meant as a compliment for client-side geocoding applications.
GeocoderJS comes with modules to integrate with various geocoding providers. The following table summarizes the features of each:
Provider | Works in browsers? | Works in Node.JS? | Supports reverse geocoding? |
---|---|---|---|
Bing | yes | untested | yes |
Geoapify | yes | untested | yes |
Geocodio | yes | untested | yes |
yes | untested | yes | |
Here | yes | untested | yes |
LocationIQ | yes | untested | yes |
Mapbox | yes | untested | yes |
Mapquest | yes | untested | yes |
OpenCage | yes | untested | yes |
OpenStreetMap | yes | untested | yes |
Radar | yes | no | yes |
TomTom | yes | untested | yes |
Yandex | yes | untested | yes |
Easily create Leaflet's to display Google Map alternatives on a website. Here's an OpenStreetMap Example:
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="dist/geocoder.js"></script>
<div id="map" style="width:800px; height:600px;"></div>
<script>
let openStreetMapGeocoder = GeocoderJS.createGeocoder('openstreetmap');
openStreetMapGeocoder.geocode('1600 Pennsylvania Ave NW, Washington, DC', function(result) {
let ll = result[0]
let mapOptions = {
center: [ll.latitude, ll.longitude],
zoom: 16
}
let map = new L.map('map', mapOptions);
L.marker([ll.latitude, ll.longitude]).addTo(map);
let layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
map.addLayer(layer);
});
</script>
The dist
folder contains the latest build. You are welcome to build your own uglified version of the script by running grunt build
.
Unit tests are handled by Jasmine. To run unit tests from the command line, use grunt test
.
The parent branch of GeocoderJS appears to have been abandoned. Contributions to this fork are welcome.