2010-09-16 115 views
5

我有一個數據庫,裏面有經度和緯度值。我一次只能顯示一個標記。我想同時顯示多個標記。我該怎麼做?使用api v2在谷歌地圖上添加多個標記

+1

歡迎湯米#1。要獲得有效的答案,您需要給我們提供更多信息,並且可能會縮小問題的範圍。以下是關於如何提出良好問題的常見引用文章:http://www.catb.org/esr/faqs/smart-questions.html – Chadwick 2010-09-16 01:40:17

回答

3

這裏是一個非常簡單的例子:

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

截圖:

Adding Multiple Markers on Google Map using api v2

相關問題