is there any methord (about google-maps api) to get the mouse's offset when mouseover (not use jquery) [closed]
GEvent.addListener(map, "mouseover", function() {
});
thanks
I am not sure if I understood your question correctly, but you may want to check out the following example.
Both the geographical coordinates as well as the DOM coordinates would update automatically as you move the mouse over the map:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps mousemove Event Demo</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false"
type="text/javascript"></script>
</head>
<body onunload="GUnload()" style="font-family: Arial; font-size: 11px;">
<div id="map" style="width: 500px; height: 300px;"></div>
<div id="div_coordinates"></div>
<div id="geo_coordinates"></div>
<script type="text/javascript">
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(39.00, -77.00), 10);
GEvent.addListener(map, "mousemove", function(latlng) {
document.getElementById('div_coordinates').innerHTML =
'Div Coordinates: ' +
map.fromLatLngToContainerPixel(latlng).x + ', ' +
map.fromLatLngToContainerPixel(latlng).y;
document.getElementById('geo_coordinates').innerHTML =
'Geographical Coordinates: ' + latlng.lat() + ', ' + latlng.lng();
});
</script>
</body>
</html>
精彩评论