簡體   English   中英

生成動態 KML 並使用 Maps API 加載它

[英]Generate dynamic KML and load it with Maps API

大家好,我的任務是創建對 200 個 ip 地址的監控,對於每個 ip,我們都有位置緯度/經度。 現在出於監控目的,我運行了 perl 腳本,它可以 ping 所有 200 台主機並更新它們在 MySql 數據庫中的狀態。

現在我想在谷歌地圖上顯示這 200 個位置並根據狀態更改標記顏色綠色 = 在線,紅色 = 離線。

我還加載了帶有連接位置和街道布線的 kml fille(這是固定的,不需要更改)

如何動態生成標記並將它們與已加載的 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>

我最終使用MySql to Maps

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM