Ashitha
Ashitha

Reputation: 81

To get the position of draggable markers

I am using draggable markers in google maps. I have to get the position of markers after dragging because i have to store the new position of marker

The code is

   var m = new GMarker(point,{draggable: true});
   m.entry_id = id;
   m.isMarker = true;
   app.entries[id].marker = m;

Upvotes: 1

Views: 697

Answers (1)

JWL
JWL

Reputation: 14201

Here is my example that will display the new location of the marker in and info-window at the new location after the marker has been dragged:

//assuming u have lat and long as latitude and longitude of the initial position
var location = new GLatLng(lat,long);   

var marker = new GMarker(location, {draggable: true});

GEvent.addListener(marker, "dragstart", function() {
  map.closeInfoWindow();
  });

GEvent.addListener(marker, "dragend", function() {
    var latlng = marker.getLatLng();
    marker.openInfoWindowHtml("New Lat : " + latlng.lat() + ", New Long : " + atlng.lng() );
  });

Am assuming you are using API version 2, the solution is a bit different for Version 3, but just a matter of change in the calling conventions sort of.

Upvotes: 1

Related Questions