get the latlng after the dragend event in leaflet? - Javascript Leaflet

Javascript examples for Leaflet:Event

Description

get the latlng after the dragend event in leaflet?

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Leaflet demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script> 
      <link rel="stylesheet" type="text/css" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css"> 
      <style id="compiled-css" type="text/css">

#map {//from  w  w  w.  j a  v a  2  s.  c  o  m
   height: 500px;
   width: 80%;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
       var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
           osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
           osm = L.tileLayer(osmUrl, {
               maxZoom: 18,
               attribution: osmAttrib
           });
       var map = L.map('map').setView([19.04469, 72.9258], 12).addLayer(osm);
       function onMapClick(e) {
           var marker = L.marker(e.latlng, {
               draggable: true,
               title: "Resource location",
               alt: "Resource Location",
               riseOnHover: true
           }).addTo(map)
               .bindPopup(e.latlng.toString()).openPopup();
           marker.on("dragend", function (ev) {
               var chagedPos = ev.target.getLatLng();
               this.bindPopup(chagedPos.toString()).openPopup();
           });
       }
       map.on('click', onMapClick);
    }

      </script> 
   </head> 
   <body> 
      <div id="map"></div>  
   </body>
</html>

Related Tutorials