2013-12-13 69 views
0

我創建了一個使用谷歌地圖的地圖,它顯示出很好的效果,並顯示了我想要的所有標記,但是點擊事件並未觸發,我看不出爲什麼我已經將腳本從在Jquery中準備好文檔的初始化函數,然後再次返回,因爲它沒有什麼區別。我將整個腳本從標題部分移到了沒有任何區別的底部。單擊谷歌地圖上的事件標記沒有觸發

我很茫然,因爲出了什麼問題,我想填充一個div,它會在點擊標記時出現在地圖的邊上。

感謝您的任何幫助,我會把它放在一個分支,但它的工作,使ajax調用一個XML文件。

<script type="text/javascript"> 
    function initialize() 
    { 
    var iconBase = 'https://dl.dropboxusercontent.com/u/102059869/'; //public drop box for icons 
    var latlng = new google.maps.LatLng(53.74,-2);//centres map around hull 
    var myOptions = {zoom: 8,center: latlng,mapTypeId: google.maps.MapTypeId.ROADMAP}; 
    var map = new google.maps.Map(document.getElementById("map"), myOptions);// Creates Map 
    var mylatlng = new google.maps.LatLng(53.745670900000000000,-0.336741299999971500); 
    var marker = new google.maps.Marker({position: mylatlng,map: map,title: 'Kingstown', icon: iconBase + 'Kingstown_Logo.png'});// Creates Marker 

      //Creates markers from data  
      $.get('PHP/SQL_MainData.php', function(d){ 
      $(d).find("marker").each(function() 
       { 
        var latlng = new google.maps.LatLng($(this).attr('latitude'),$(this).attr('longitude')); //gets Google LatLng 
        var myMarker = new google.maps.Marker(
          {position: latlng, 
           map: map, 
           title:$(this).attr('traffic'), 
           icon: iconBase + 'caution.png' 
          }); 

        marker.info = new google.maps.InfoWindow({content: '<b>Info:</b> ' + $(this).attr('traffic')}); 

       }); 
      }); 

      google.maps.event.addListener(marker, 'click', function() { 
         marker.info.open(map, marker); 
         $('#info-area span').text(marker.info); 
         }); 
     }   
</script> 

回答

0

的google.maps.Marker是 「myMarker」

要添加的偵聽器,以標記(它不是google.maps.Marker)。

   var latlng = new google.maps.LatLng($(this).attr('latitude'),$(this).attr('longitude')); //gets Google LatLng 
       var myMarker = new google.maps.Marker(
         {position: latlng, 
          map: map, 
          title:$(this).attr('traffic'), 
          icon: iconBase + 'caution.png' 
         }); 

       marker.info = new google.maps.InfoWindow({content: '<b>Info:</b> ' + $(this).attr('traffic')}); 

      }); 
     }); 

     google.maps.event.addListener(myMarker, 'click', function() { 
        marker.info.open(map, myMarker); 
        $('#info-area span').text(marker.info); 
        }); 
相關問題