Need to know coordinates of manualy draggable marker on map

2,841 views
Skip to first unread message

gr33tx

unread,
Sep 11, 2012, 4:13:32 AM9/11/12
to leafl...@googlegroups.com
I'm new to javascript and Jquery. Please, help me with advice. I need user can set coordinates manually. I can drag marker but cant get its coordinates. How to get coordinates of marker on "enddrag"? Thanks 

Guillaume DUGAS

unread,
Sep 11, 2012, 4:31:52 AM9/11/12
to leafl...@googlegroups.com
marker.on('dragend', function (e) {
 var coords = e.target.latlng;
 var lat = coords.lat;
 var lng = coords.lng;
 // ...
});

2012/9/11 gr33tx <svsv...@gmail.com>
I'm new to javascript and Jquery. Please, help me with advice. I need user can set coordinates manually. I can drag marker but cant get its coordinates. How to get coordinates of marker on "enddrag"? Thanks 

--
 
 
 

Guillaume DUGAS

unread,
Sep 11, 2012, 4:33:21 AM9/11/12
to leafl...@googlegroups.com
Sorry for the error, here the answer:

marker.on('dragend', function (e) {
 var coords = e.target.getLatLng();
 var lat = coords.lat;
 var lng = coords.lng;
 // ...
});

2012/9/11 Guillaume DUGAS <dugas.g...@gmail.com>

gr33tx

unread,
Sep 11, 2012, 5:10:24 AM9/11/12
to leafl...@googlegroups.com
Thanks a lot DUGAS !

gr33tx

unread,
Sep 11, 2012, 5:57:18 AM9/11/12
to leafl...@googlegroups.com

L.marker([54.7067, 20.50967]).addTo(map)
.bindPopup("<b> 1 </b>")
.dragging.enable();
//alert(toString(map.marker.getLatLng()));


marker.on('dragend', function (e) {
var coords = e.target.getLatLng();
var lat = coords.lat;
var lng = coords.lng;
alert (lat);
// ...
});

Sorry, it doesn work. How to connect it with my marker? Probably:

 L.marker.on('dragend', function (e) {

var coords = e.target.getLatLng();
var lat = coords.lat;
var lng = coords.lng;
alert (lat);
// ...
});

??? but its not work too

Guillaume DUGAS

unread,
Sep 11, 2012, 6:07:37 AM9/11/12
to leafl...@googlegroups.com
You just need to assign your marker to your "marker" var, like that:

var marker = L.marker([54.7067, 20.50967]).addTo(map)
...
 
and then, you can bind your event:

marker.on('dragend', function (e) {
...

all the basics are explained here: http://leaflet.cloudmade.com/examples/quick-start.html


Good luck !

2012/9/11 gr33tx <svsv...@gmail.com>

--
 
 
 

gr33tx

unread,
Sep 11, 2012, 8:20:14 AM9/11/12
to leafl...@googlegroups.com

Thanks a lot! It's work!
Reply all
Reply to author
Forward
0 new messages