我想從PostgreSQL數據庫中提取經度和緯度坐標,并在傳單地圖上顯示這些坐標。使用下面的代碼,我能夠查詢數據庫中的數據并在瀏覽器上打印數據。索引.php<!DOCTYPE html><html><head><meta charset=utf-8"> <title>Map</title></head><body onload="init()"><h1>Map</h1><div><?php$conn = pg_connect("host=localhost port=5432 dbname=visualization user=postgres password=*******");$result = pg_query($conn,"SELECT lon,lat FROM pms_tunnel WHERE lon is not NULL or lat is not NULL");echo "<table>";while($row=pg_fetch_assoc($result)){ echo "<tr>"; echo "<td width='200'>" . $row['lon'] . "</td>"; echo "<td width='200'>" . $row['lat'] . "</td>"; echo "</tr>";}echo "</table>";pg_close($conn);?></div></body></html>使用下面的代碼,我能夠使用傳單顯示世界地圖,并在1經緯度坐標上繪制標記。遵循 https://leafletjs.com/examples/quick-start/ 教程//Map Leafletvar mymap = L.map('mapid').setView([37.541999, 126.752747], 17);L.tileLayer('http://xdworld.vworld.kr:8080/2d/Base/201802/{z}/{x}/{y}.png',{ maxZoom: 20, subdomains:['mt0','mt1','mt2','mt3']}).addTo(mymap);var marker = L.marker([37.541999, 126.752747]).addTo(mymap); // 1 longitude latitude coord現在,我不想從經度和緯度坐標中放置1個標記,而是在地圖上顯示數據庫中的所有坐標,并在每個坐標上放置標記。如何做到這一點?
1 回答

12345678_0001
TA貢獻1802條經驗 獲得超5個贊
你可以混合使用php和js來完成這個任務,就像下面的例子一樣:
<?php while($row=pg_fetch_assoc($result)){ ?>
var marker = L.marker([<?php echo $row['lon']?>,<?php echo $row['lat'] ?>]).addTo(mymap);
<?php } ?>
- 1 回答
- 0 關注
- 74 瀏覽
添加回答
舉報
0/150
提交
取消