2008/08/08

Google Map API: Get a marker's lat/lon

This script is to make a marker when you click the map. The idea is at first to obtain lat/lon parameters, then draw a marker overlay on the map.

GEvent.addListener(map, “click”,
function(marker, point) {
map.addOverlay(new createMarker(point));
}
);

function createMarker(point) {
var marker = new GMarker(point);
GEvent.addListener( marker, “click”,
function() {
//show the longitude
document.getElementById(”message1″).innerHTML = point.lat();
//show the latitude
document.getElementById(”message2″).innerHTML = point.lng();
}
);
return marker;
}

没有评论: