简体   繁体   English

当标记之一是 null 经度和纬度时,leaflet map 不显示所有标记

[英]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 the other marker from my map still work, even one of the marker get null longitude and latitude:) this is some of my code: 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();
            });
            ;
            ';
        }

    }

can someone get me some advice to solve this problem?, thanks for read this:)有人可以给我一些建议来解决这个问题吗?谢谢阅读:)

you can try something like this to skip null latitude and longitude:你可以尝试这样的事情来跳过 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.

相关问题 如何在一个 map 中显示 3 个纬度和经度(标记)? - how to display 3 latitude & longitude (Marker) in one map? 在传单中查找已保存标记的纬度和经度 - find latitude & longitude of saved marker in leaflet 在反应传单中获取标记的纬度和经度 - Getting latitude and longitude of a marker in react-leaflet Leaflet 动画标记不显示经纬度 - Leaflet animated marker not displaying the latitude and longitude Laravel和谷歌地图:foreach纬度/经度显示标记或地图 - Laravel and google maps : foreach latitude/longitude show marker or map 移动谷歌地图标记点时,使用纬度和经度更新数据库 - Update db with latitude and longitude when google map marker point is move 在 iFrame 中显示纬度和经度标记值 - show Latitude and Longitude marker values in iFrame 使用 SQL 数据库和 Leaflet Map 在 Z9E0DA8438E1E38B81CDD3 - Display Marker Using Latitude And Longitude From SQL Database With Leaflet Map In ASP.NET CORE MVC 如何标记搜索变得可拖动并在 leaflet 中给出经度和纬度 - How to marker search become draggable and give the Longitude & latitude in leaflet 如何通过leaflet js中的点击标记获取最新的经纬度值? - How to get the latest value of latitude and longitude with click marker in leaflet js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM