Search code examples
javascriptleafletmapbox

Using Leaflet.js how do I get map lat/lon on drag end?


I am using the leaflet.js and integrate it with my code very easily . I am unable to find the co-ordinates on drag end event like in google map . So please can anyone suggest how to do that . Any kind of help and suggestion is appreciated.

var map = L.map('map', {center: latlng, zoom: 13, layers: [tiles]});

var markers = L.markerClusterGroup({ chunkedLoading: true });

showData(map,markers);

map.on('dragend',function(e){
  console.log("console.log", e);
  console.log(e.target.latLngToContainerPoint);
  //showData(map,markers,e.target._animateToCenter.lat, e.target._animateToCenter.lng , e.distance)
});

Solution

  • Can you not just get the map center on drag end?

    map.on('dragend',function(e){
      console.log(map.getCenter());
    });
    

    See example http://codepen.io/sphvn/pen/GJbxBw?editors=001

    If this isn't what you are after can you please clarify your question.