Get started with leaflet-locatecontrol CDN

MIT licensed

Plugin The Leaflet.locatecontrol adds locate button for user location in Leaflet maps.

Tags:
  • leaflet
  • maps
  • mobile

Stable version

Copied!

How to start using leaflet-locatecontrol CDN


// Include Leaflet and LocateControl libraries
L.Icon.Default.imagePath = 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/';

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

// Include LocateControl library from CDN
L.control.locate({
  position: 'topright',
  flyTo: false,
  watchUserLocation: false
}).addTo(map);

// Add a marker at the user's location
map.on('locationfound', function(e) {
  const marker = L.marker(e.latlng).addTo(map);
  marker.bindPopup('You are here').openPopup();
});
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions