Hi all,
I'm new to Javascript and also Maps in Google. my task is :
- to allow user to add marker on the map
- display an info window when the user click on the marker
- display 'Kuala Lumpur City Center' in the info window if the marker pointing to the Kuala Lumpur City Center and 'Unknown location' for other locations.
My problem is I can't even display an info window after the marker is added. Can I add a new event within the same function? the code only works for adding the marker. The code below is after I edited from the google maps:
function MyApplication() {
this.counter = 0;
this.map = new GMap2(document.getElementById("map_canvas"));
this.map.setCenter(new GLatLng(3.145423,101.696883), 13);
var myEventListener = GEvent.bind(this.map, "click", this, function(overlay, latlng) {
if (this.counter == 0) {
if (latlng) {
this.map.addOverlay(new GMarker(latlng))
this.counter++;
} else if (overlay instanceof GMarker) {
//This code is never executed as the event listener is
//removed the second time this event is triggered
this.removeOverlay(marker)
}
} else {
GEvent.removeListener(myEventListener);
}
});
}
function initialize() {
var application = new MyApplication();
}
function createMarker(latlng) {
var marker = new GMarker(latlng);
GEvent.addListener(marker,"click", function() {
marker.openInfoWindowHtml('Petronas Twin Tower');
});
return marker;
}
thanks in advance. I've been cracking my head for almost 2 weeks. :( please help me...