The included JavaScript snippet should do the following:
When the user clicks on the map, initialize headMarker and draw a circle around it (polygon)
When the user clicks inside the circle, initialize tailMarker and draw a path between the two markers
1 happens as expected. But as the user clicks inside the circle, in function(overlay,point) , overlay not null, and point is null. Because of this, the code cannot 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}); } });
source share