为了账号安全,请及时绑定邮箱和手机立即绑定

当标记之一为空经度和纬度时,传单地图不显示所有标记

当标记之一为空经度和纬度时,传单地图不显示所有标记

PHP
慕码人8056858 2023-03-04 16:46:46
我最近从我的学校得到一个任务,我使用传单制作了一张简单的地图,但是我有一个问题,我的地图上的标记没有显示,当其中一个标记在数据库中的经度和纬度上为空时,我想要我地图上的另一个标记仍然有效,即使其中一个标记的经度和纬度都为空 :) 这是我的一些代码:            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();            });            ;            ';        }    }有人能给我一些解决这个问题的建议吗?感谢阅读本文:)
查看完整描述

1 回答

?
杨__羊羊

TA贡献1943条经验 获得超7个赞

你可以尝试这样的事情来跳过空纬度和经度:


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']);

}

:)


查看完整回答
反对 回复 2023-03-04
  • 1 回答
  • 0 关注
  • 75 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信