2014-01-30 260 views
5

簡單的問題:鏈接標記到URL谷歌地圖

我試圖將我的標記鏈接到谷歌地圖(API v3)上的外部網址。 現在只需使用http://www.google.com作爲鏈接。

的Javascript:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
<script> 
    function initialize() { 
     var myLatlng = new google.maps.LatLng(-30.021664, 30.901578); 
     var mapOptions = { 
     zoom: 15, 
     center: myLatlng, 
     scrollwheel: false, 
     disableDefaultUI: true 
     } 
    var map = new google.maps.Map(document.getElementById('ContactMap'), mapOptions); 
    var image = '/Assets/Images/Icons/MapMarker.png'; 

     var marker = new google.maps.Marker({ 
      position: myLatlng, 
      map: map, 
      animation: google.maps.Animation.DROP, 
      icon: image, 
      title: 'Perspex' 
     }); 
    } 
    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
+0

'將我的標記鏈接到外部網址'的意思? – Praveen

+0

你的意思是什麼鏈接?要點擊標記打開另一個鏈接? –

回答

14

您需要添加一個谷歌地圖點擊event這個標記:

google.maps.event.addListener(marker, 'click', function() { 
    window.location.href = 'http://www.google.com'; 
}); 

做這個定義之後。

+0

不錯,很容易!謝謝。 – Dale