簡體   English   中英

谷歌地圖-跟蹤信息窗口內容上的點擊事件

[英]google maps - track click event on info window content

我的谷歌地圖代碼是:

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);
    });
}

我的問題是在信息窗口內容中單擊事件后如何跟蹤分析?

在此先感謝,Irena

看看Analytics事件跟蹤指南

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

還請注意,您的infowindow.setContent(<div...缺少'之前('<div

更新

要在信息窗口內的鏈接上設置onclick事件,必須使用jquery live事件。 這是因為直到我們單擊標記以顯示信息窗口后,鏈接才存在。

因此要在信息窗口中的<div>上實現click事件,您需要執行以下操作:

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() {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM