Clicking inside a polygon in Google Maps

Posted by amarsh-anand on Stack Overflow See other posts from Stack Overflow or by amarsh-anand
Published on 2010-05-19T12:19:17Z Indexed on 2010/05/21 15:50 UTC
Read the original article Hit count: 254

Filed under:
|
|
|

The included JavaScript snippet is supposed to do the following:

  1. As the user clicks on the map, initialize headMarker and draw a circle (polygon) around it

  2. As the user clicks inside the circle, initialize tailMarker and draw the path between these two markers

1 is happening as expected. But as the user clicks inside the circle, in the function(overlay,point), overlay is non-null while point is null. Because of this, the code fails to initialize tailMarker.

Can someone tell me a way out.

GEvent.addListener(map, "click", function(overlay,point) {
    if (isCreateHeadPoint) {
        // add the head marker
        headMarker = new GMarker(point,{icon:redIcon,title:'0'});
        map.addOverlay(headMarker);
        isCreateHeadPoint = false;
        // draw the circle
        drawMapCircle(point.lat(),point.lng(),1,'#cc0000',2,0.8,'#0',0.1);
    } else {
        // add the tail marker
        tailMarker = new GMarker(point,{icon:greenIcon,title:''});
        map.addOverlay(tailMarker);
        isCreateHeadPoint = true;
        // load thes path from head to tail
        direction.load("from:" + headMarker.getPoint().lat()+ ", " + 
                        headMarker.getPoint().lng()+ " " +
                       "to:" + tailMarker.getPoint().lat() + "," +
                        tailMarker.getPoint().lng(), 
                       {getPolyline:true}); 
    }
});

© Stack Overflow or respective owner

Related posts about google-maps

Related posts about overlay