2011-11-03 27 views
0

我的谷歌地圖的代碼是:谷歌地圖 - 在信息窗口內容的軌道click事件

function initialize(mapdata){ 
    var LatLng=new google.maps.LatLng(mapdata[0],mapdata[1]); 
    var myOptions= { 
     zoom:16, 
     scaleControl:true, 
     streetViewControl:false, 
     panControl:true, 
     mapTypeControl:true, 
     center:new google.maps.LatLng(mapdata[0],mapdata[1]), 
     mapTypeId:google.maps.MapTypeId.ROADMAP 
    }; 
    var map=new google.maps.Map(document.getElementById("map"), myOptions); 
    document.getElementById("map").style.height="200px"; 
    document.getElementById("map").style.width="450px"; 
    var infowindow=new google.maps.InfoWindow(); 
    var marker=new google.maps.Marker({position:LatLng}); 
    marker.setMap(map); 
    google.maps.event.addListener(marker,'mouseover',function(){ 
     infowindow.setContent(<div style="text-align:right; font-size:8pt; color:black;">click here<a href="http://www.google.com/"></a> </div>'); 
     infowindow.open(map,marker); 
    }); 
} 

我的問題是我怎麼可以跟蹤與分析在信息窗口內容點擊事件之後?

由於提前, 伊雷娜

+0

先格式化您的代碼。謝謝 – hsz

回答

1

看看analytics Event Tracking Guide

<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);">Play</a> 

也注意到,您的infowindow.setContent(<div...錯過了'('<div

UPDATE

設置在infowindow內的鏈接上的onclick事件,你必須使用jquery直播活動。這是因爲鏈接不存在,直到我們點擊標記來顯示infowindow。

因此要實現你想要做的事,如信息窗口內對<div>的單擊事件:

google.maps.event.addListener(marker,'mouseover',function(){ 
     infowindow.setContent('<div style="text-align:right; font-size:8pt; color:black;" id="some_id_here">click here<a href="http://www.google.com/"></a> </div>'); 
     infowindow.open(map,marker); 
}); 
$("#some_id_here").live('click', function() { 
    alert('click'); 
}); 

記住,我已經給div中id="some_id_here"

如果你有多個信息窗口的在同一時間打開,您需要在重置它之前解除綁定直播活動。否則有可能live('click')事件綁定了多次。要達到此目的,您應該這樣做:

$("#some_id_here").die('click').live('click', function() { 
+0

,但我已經知道如何跟蹤分析中的事件。問題是我不知道如何在信息窗口代碼中實現點擊事件 – Irena

+0

@Irena更新了我的文章 –

+0

太棒了!有用。 – Irena