views:

68

answers:

1

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

A: 

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&amp;amp;v=2&amp;amp;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>
Daniel Vassallo