2013-12-10 63 views
0

我在每個標記上添加標題時遇到問題,想知道如何在每個標記上添加這些標題?下面在谷歌地圖上放置標記標題

<div id="map" style="width: 700px; height: 400px;"></div> 

    <script type="text/javascript"> 
    var locations = [ 

是標記

 ['SM North Edsa', 14.65696, 121.03017, 1], 
     ['SM Mall of Asia', 14.53502, 120.98348, 2], 
     ['SM Megamall', 14.58392, 121.05690, 3], 
     ['Trinoma', 14.65353, 121.03322, 4], 
     ['SM The Annex', 14.65687, 121.02683, 5], 
     ['Gateway', 14.62276, 121.05374, 6], 
     ['SM Iloilo', 10.71415, 122.55109, 7], 

    ]; 

代碼,這裏是整個網頁的代碼的其餘部分。

var map = new google.maps.Map(document.getElementById('map'), { 
     zoom: 10, 
     center: new google.maps.LatLng(14.59175, 120.98295), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    var infowindow = new google.maps.InfoWindow(); 

    var marker, i; 

    for (i = 0; i < locations.length; i++) { 
     marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
     map: map 
     }); 

     google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     return function() { 
      infowindow.setContent(locations[i][0]); 
      infowindow.open(map, marker); 
     } 
     })(marker, i)); 
     } 
     </script>+ 

回答

0
marker = new google.maps.Marker({ 
    position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
    map: map, 
    title: locations[i][0] 
    }); 

參考this tutorial