Man this is hard work. It probably takes a lot of time before you
really get the hang of it.
Anyways I produced this code:
marker = new Array();
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(52.107, 4.265), 15);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_HYBRID_MAP);
map.disableDoubleClickZoom();
GEvent.addListener(map, 'click', createMarker);
}
}
function createMarker(overlay, latlng){
key = marker.length;
marker[key] = new GMarker(latlng, {draggable: true});
map.addOverlay(marker[key]);
GEvent.addListener(marker[key], 'click', function(){
marker[key].openInfoWindowHtml('LatLng: ' +
marker[key].getLatLng
());
});
}
function removeMarker(key){
map.removeOverlay(marker[key]);
}
Creating the nodes works like a charm, however opening an info window
doesn't work. I didn't get the removeMarker to work either.
btw: thanks for all the help so far guys.
PS: yeah you're right, it's not a bug but just something I expected to
work a bit different...
On Mar 8, 1:56 pm, Mike Williams <[email protected]> wrote:
> If you want more than one marker, then you should use a createMarker()
> function to hold context on the relevant variables.
>
> Unless you've got a really good reason for using double click, I'd
> recommend using single clicks. Use map:click to create a marker, and
> have <input type="button" value="Delete" onclick="deleteLastMarker()" />
> at the bottom of the info window.
>
> Store a global copy of the "marker" variable when the info window opens.
>
> GEvent.addListener(marker, "click", function(){
> lastMarker = marker;
> marker.openInfoWindowHtml('LatLng: ' + marker.getLatLng()
> +'<input type="button" value="Delete" onclick="deleteLastMarker()" />'
> );
>
> });
>
> function deleteLastMarker() {
> map.closeInfoWindow();
> map.removeOverlay(lastMarker);
>
> }
>
> Your "map" variable will also need to be global.
>
> [All this is untested, so you might have to tweak it a bit.]
>
> --http://econym.org.uk/gmap
> The Blackpool Community Church Javascript Team
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---