使用api v2在Google地图上添加多个标记 [英] Adding Multiple Markers on Google Map using api v2

查看:127
本文介绍了使用api v2在Google地图上添加多个标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,里面有经度和纬度值。我一次只能显示一个标记。我想同时显示多个标记。

解决方案

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

 <!DOCTYPE html> 
< html>
< head>
< meta http-equiv =content-typecontent =text / html; charset = UTF-8/>
< title> Google地图多个标记< / title>
< script src =http://maps.google.com/maps?file=api&amp;v=2&amp
type =text / javascript>< /脚本>
< / head>
< body>
< div id =mapstyle =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', [$ Man $ B ['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],地点[i] [2]))
);
}
< / script>
< / body>
< / html>

截图:


I have got a database with latitude and longitude values in it. I can show only one marker at a time. I would like to show multiple markers at the same time. How can I do it?

解决方案

Here's a very basic example:

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

Screenshot:

这篇关于使用api v2在Google地图上添加多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆