Google Maps Guru's,
It has been a while since I have tried building a webpage using Google
Maps and now using it again I ran into a problem:
I would like to be able to create a marker when double clicking the
map (at the clicked location) and remove the marker when double
clicking it. The maximum amount of markers should be 1. So you should
be able to create, delete and create again.
Creating the marker works fine, but when I want to delete it it seems
to want to create it at the same time again, thus not deleting the
marker and setting the number of markers to 0.
My code:
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(52.214338608258196, -1.0546875), 15);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_HYBRID_MAP);
map.disableDoubleClickZoom();
var markers = 0;
GEvent.addListener(map, "dblclick", function(overlay, latlng){
if(markers == 0){
var marker = new GMarker(latlng, {draggable:
true});
map.addOverlay(marker);
markers = 1;
GEvent.addListener(marker, "dragstart",
function()
{ marker.closeInfoWindow(); });
GEvent.addListener(marker, "click", function()
{ marker.openInfoWindowHtml('LatLng: ' + marker.getLatLng()); });
GEvent.addListener(marker, "dblclick",
function(){
map.removeOverlay(marker);
markers = 0;
});
}
});
}
}
I put an example online so you guys can see what it in action:
http://sitedezign.net
Can anybody tell me where It's going wrong (and what to do about it)?
Thanks
PS: I can vaguely remember the webpages about the google maps api to
be much clearer in the past. Is it true there used to be a lot more
documentation that explained the lot (to my opinion) a lot more
properly?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---