Get started with esri-leaflet-geocoder CDN

Apache-2.0 licensed

Esri-Leaflet-Geocoder is a plugin that integrates Esris geocoding service into Leaflet maps.

Tags:
  • geocoding
  • ArcGIS
  • Leaflet

Stable version

Copied!

How to start using esri-leaflet-geocoder CDN


// Include required libraries
L.esri.accessToken = "YOUR_ARCGIS_ONLINE_ACCESS_TOKEN"; // Replace with your ArcGIS Online access token

// Create a map
const map = L.map('mapid').setView([51.505, -0.09], 13);

// Include esri-leaflet-geocoder library
L.esri.util.registerPlugin(/esri-leaflet-geocoder.js/);

// Initialize the geocoder plugin
const geocoder = L.esri.Geocoding.geocoder();

// Add a search control to the map
const searchControl = L.esri.Controls.Geocoding.geocoding({
  position: 'topright',
  geocoder: geocoder,
});
map.addControl(searchControl);

// Add a marker to the map that moves to the location found by the geocoder
const marker = L.marker([], { draggable: false }).addTo(map);

// Bind the geocoder to the search control
searchControl.on('geocode:result', function (event) {
  marker.setLatLng(event.result.location);
});
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions