将标题放在谷歌地图上的标记上

时间:2013-12-10 03:18:44

标签: javascript google-maps google-maps-api-3

我在每个标记上添加标题时遇到问题,有关如何在每个标记上添加标题的任何想法吗?

<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>+

1 个答案:

答案 0 :(得分: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