簡體   English   中英

如何在 Leaflet.js 中添加多個標記?

[英]How to add multiple markers in Leaflet.js?

我想在我的地圖中添加多個標記以精確定位以下坐標。

  1. 北緯 11.8166°,東經 122.0942°
  2. 北緯 11.9804°,東經 121.9189°
  3. 北緯 10.7202°,東經 122.5621°
  4. 北緯 11.3889°,東經 122.6277°
  5. 北緯 10.5929°,東經 122.6325°

你可以這樣做:

希望能幫助到你 :)

 var locations = [ ["LOCATION_1", 11.8166, 122.0942], ["LOCATION_2", 11.9804, 121.9189], ["LOCATION_3", 10.7202, 122.5621], ["LOCATION_4", 11.3889, 122.6277], ["LOCATION_5", 10.5929, 122.6325] ]; var map = L.map('map').setView([11.206051, 122.447886], 8); mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>'; L.tileLayer( 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '&copy; ' + mapLink + ' Contributors', maxZoom: 18, }).addTo(map); for (var i = 0; i < locations.length; i++) { marker = new L.marker([locations[i][1], locations[i][2]]) .bindPopup(locations[i][0]) .addTo(map); }
 #map { width: 600px; height: 400px; }
 <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script> <div id='map'></div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM