it would be like this :
开发者_开发技巧<div id="map_canvas" style="width: 500px; height: 300px;float:left;"></div>
left:(<=300) top:(<=500)
GEvent.addListener(map, "click", function() {
//aFn()
});
i want to make a polyline when i clicked:
var polyline = new GPolyline([onePoint,twoPoint], "#ff0000", 5);
map.addOverlay(polyline);
thanks
I think you may want to check the fromLatLngToContainerPixel() method, which computes the pixel coordinates of the given geographical point in the DOM element that contains the map on the page.
You may want to try the following example. Click anywhere on the map to get the container coordinates:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps fromLatLngToContainerPixel Demo</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false"
type="text/javascript"></script>
</head>
<body onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px;"></div>
<script type="text/javascript">
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(39.00, -77.00), 10);
GEvent.addListener(map, "click", function(overlay, latlng) {
alert(map.fromLatLngToContainerPixel(latlng).x + ', ' +
map.fromLatLngToContainerPixel(latlng).y)
});
}
</script>
</body>
</html>
精彩评论