繁体   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