【问题标题】:Adding Multiple Markers on Google Map using api v2使用 api v2 在 Google Map 上添加多个标记
【发布时间】:2010-09-16 01:30:14
【问题描述】:

我有一个包含纬度和经度值的数据库。我一次只能显示一个标记。我想同时显示多个标记。我该怎么做?

【问题讨论】:

  • 欢迎来到 Stackoverflow Tommy。要获得有效的答复,您需要向我们提供更多信息,并可能将问题缩小到更具体的范围。这是一篇关于如何提出好问题的经常被引用的文章:catb.org/esr/faqs/smart-questions.html

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


【解决方案1】:

这是一个非常基本的例子:

<!DOCTYPE html>
<html> 
<head> 
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
  <title>Google Maps Multiple Markers</title> 
  <script src="http://maps.google.com/maps?file=api&amp;v=2&amp"
          type="text/javascript"></script>
</head> 
<body>
  <div id="map" style="width: 500px; height: 400px;"></div>

  <script type="text/javascript">
    var locations = [
      ['Bondi Beach',    -33.890542, 151.274856],
      ['Coogee Beach',   -33.923036, 151.259052],
      ['Cronulla Beach', -34.028249, 151.157507],
      ['Manly Beach',    -33.800128, 151.282085],
      ['Maroubra Beach', -33.950198, 151.259302]
    ];

    var map = new GMap2(document.getElementById('map'));
    var i;

    map.setCenter(new GLatLng(-33.92, 151.25), 10);

    for (i = 0; i < locations.length; i++) {  
      map.addOverlay(
        new GMarker(new GLatLng(locations[i][1], locations[i][2]))
      );
    }
  </script>
</body>
</html>

截图:

【讨论】:

    猜你喜欢
    • 2014-12-24
    • 2013-03-14
    • 1970-01-01
    • 2015-08-14
    • 2013-09-20
    • 1970-01-01
    • 2013-09-13
    • 2012-12-01
    • 2013-06-04
    相关资源
    最近更新 更多