生成动态 KML 并使用地图加载它 API

Generate dynamic KML and load it with Maps API

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

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

我还加载了带有连接位置和街道布线的 kml fille(这是固定的,不需要更改)

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

或者如果有其他解决方案我愿意考虑。

这是我正在加载我的 kml fille 的示例:

<!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>

我最终使用了 MySql to Maps