Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 生成动态KML并使用Maps API加载它_Javascript_Php_Api_Google Maps_Kml - Fatal编程技术网

Javascript 生成动态KML并使用Maps API加载它

Javascript 生成动态KML并使用Maps API加载它,javascript,php,api,google-maps,kml,Javascript,Php,Api,Google Maps,Kml,大家好,我的任务是创建200个ip地址的监控,每个ip都有位置纬度/经度。现在为了监控的目的,我运行了perl脚本,它ping所有200台主机并更新它们在MySql数据库中的状态 现在我想在谷歌地图上显示这200个位置,并根据状态改变标记颜色绿色=在线,红色=离线 此外,我还加载了kml文件,其中包含连接位置和街道布线(这是固定的,无需更改) 如何动态生成标记并将它们与已加载的kml填充一起显示 如果有任何其他的解决方案,我愿意考虑。 以下是我正在加载kml文件的示例: <!DOCTYPE

大家好,我的任务是创建200个ip地址的监控,每个ip都有位置纬度/经度。现在为了监控的目的,我运行了perl脚本,它ping所有200台主机并更新它们在MySql数据库中的状态

现在我想在谷歌地图上显示这200个位置,并根据状态改变标记颜色绿色=在线,红色=离线

此外,我还加载了kml文件,其中包含连接位置和街道布线(这是固定的,无需更改)

如何动态生成标记并将它们与已加载的kml填充一起显示

如果有任何其他的解决方案,我愿意考虑。 以下是我正在加载kml文件的示例:

<!DOCTYPE html>
<html>
<head>
    <title>KML Layers</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <script
        src="https://maps.googleapis.com/maps/api/js?key=MY API&callback=initMap&libraries=&v=weekly"
        defer
    ></script>
    <style type="text/css">
        /* Always set the map height explicitly to define the size of the div
         * element that contains the map. */
        #map {
            height: 100%;
        }

        /* Optional: Makes the sample page fill the window. */
        html,
        body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
    <script>
        "use strict";

        function initMap() {
            const map = new google.maps.Map(document.getElementById("map"), {
                zoom: 12,
                center: {
                    lat: 35.928926,
                    lng: 14.462688
                }
            });
            const ctaLayer = new google.maps.KmlLayer({
                url: "MY KML ADDRESS",
                map: map
            });
        }
    </script>
</head>
<body>
<div id="map"></div>
</body>
</html>

KML层
/*始终明确设置贴图高度以定义div的大小
*包含映射的元素*/
#地图{
身高:100%;
}
/*可选:使示例页面填充窗口*/
html,
身体{
身高:100%;
保证金:0;
填充:0;
}
“严格使用”;
函数initMap(){
const map=new google.maps.map(document.getElementById(“map”){
缩放:12,
中心:{
纬度:35.928926,
液化天然气:14.462688
}
});
const ctaLayer=new google.maps.kmlayer({
url:“我的KML地址”,
地图:地图
});
}
我最终使用了

有关如何从MySQL加载标记,请参阅。您可以将该代码与Kmlayer结合起来。谢谢,我最后做了类似的事情