Reputation: 437
I am using the Gmaps.js script. I can not find how to get latitude and longitude if I move Marker with draggable option
map = new GMaps({
div: '#map',
lat: -24.836536,
lng: -65.393051,
draggable: true,
dragend: function(e) {
//get latitude and longitude?????
alert('click 01');
}
});
map.addMarker({
lat: -12.043333,
lng: -77.028333,
title: 'Lima',
draggable: true,
dragend: function(e) {
//get latitude and longitude?????
alert('click 02');
}
});
this is what I want to do, but with gmaps.js http://ubilabs.github.io/geocomplete/examples/draggable.html
Gracias!!!!! Thank you!!!!
Upvotes: 1
Views: 2499
Reputation: 437
Solucionado
map.addMarker({
//lat: -24.788333333333,
//lng: -65.410555555556,
lat: lat,
lng: lng,
draggable: true,
dragend: function(event) {
var lat = event.latLng.lat();
var lng = event.latLng.lng();
alert('draggable '+lat+" - "+ lng);
},
title: 'Marker #' + index,
infoWindow: {
content: content
}
});
Upvotes: 5
Reputation: 161404
The google.maps.Map
is map.map, to get the center on drag use:
map.map.getCenter()
dragend event listener:
dragend: function(e) {
console.log(e);
document.getElementById('mapinfo').innerHTML = "map center=" + map.map.getCenter().toUrlValue(6);
}
The google.maps.Marker
dragend event returns a google.maps.MouseEvent, to get its location, use
e.latLng
dragend event:
dragend: function(e) {
document.getElementById('info').innerHTML = "marker position=" + e.latLng.toUrlValue(6);
}
Upvotes: 0