0
我是JavaScript新手,也是谷歌地圖。我的任務是:如何在添加一次後添加另一個事件偵聽器..?
- ,以允許用戶在地圖上添加標記
- 顯示的信息窗口時,在信息窗口,如果標記標記
- 顯示「吉隆坡城市中心」的用戶點擊指向吉隆坡市中心和其他地點的「未知地點」。
我的問題是我添加標記後,甚至不能顯示信息窗口。我可以在同一功能中添加新事件嗎?該代碼僅適用於添加標記。下面的代碼是後我從谷歌地圖編輯:
功能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();
}
功能createMarker(經緯度){
var marker = new GMarker(latlng);
GEvent.addListener(marker,"click", function() {
marker.openInfoWindowHtml('Petronas Twin Tower');
});
return marker;
}
提前致謝。我已經開了近2個星期了。 :(請幫我...