[英]leaflet map doesn't show all the marker when one of the marker is null longitude and latitude
I recently get a task from my School, I made a simple map using leaflet, but I have a problem, the marker from my map doesn't show, when one of the markers get null on longitude and latitude from the database, I Want我的 map 中的另一個標記仍然有效,甚至其中一個標記得到 null 經度和緯度:) 這是我的一些代碼:
while($row = mysqli_fetch_assoc($data)) {
if($row['latitude'] == 0 ){
// what should i do here, ????
// var_dump('place_name');
}else{
// add marker to map
$marker .= 'var marker = L.circle(['.$row['latitude'].', '.$row['longitude'].'],
{
color: "red",
fillColor: "#f03",
fillOpacity: 0.5,
radius: 2000
}
).addTo(map).bindPopup("'.$row['place_name'].'").openPopup().on("mouseover", function (e) {
this.openPopup();
}).on("mouseout", function (e) {
this.closePopup();
});
;
';
}
}
有人可以給我一些建議來解決這個問題嗎?謝謝閱讀:)
你可以嘗試這樣的事情來跳過 null 緯度和經度:
while ($row = mysqli_fetch_assoc($data)) {
$latitude = (float)$row['latitude'];
$longitude = (float)$row['longitude'];
if ($latitude === 0 && $longitude === 0) {
continue;
// what should i do here, ????
// var_dump('place_name');
}
// add marker to map
$marker .= sprintf('var marker = L.circle([ %s, %s],
{
color: "red",
fillColor: "#f03",
fillOpacity: 0.5,
radius: 2000
}
).addTo(map).bindPopup("%s").openPopup().on("mouseover", function (e) {
this.openPopup();
}).on("mouseout", function (e) {
this.closePopup();
});
;
', $latitude, $longitude, $row['place_name']);
}
:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.