Draggable Marker

Try It Out

Click-and-drag the marker and notice the values in the form fields changing

Code

          marker.on("drag", function(e) {
            var marker = e.target;
            var position = marker.getLatLng();
            document.getElementById("frm_lat").value = position.lat;
            document.getElementById("frm_long").value = position.lng;
        });
        

View the source of this page to see how the map is created. Notice:

  • The marker draggable property is set to true
  • We listen for the drag event and update two elements with the latitude and longitude

Next Example Previous