Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.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 JS:如何制作动态谷歌地图多段线?_Javascript_Google Maps_Google Maps Api 3_Get_Google Polyline - Fatal编程技术网

Javascript JS:如何制作动态谷歌地图多段线?

Javascript JS:如何制作动态谷歌地图多段线?,javascript,google-maps,google-maps-api-3,get,google-polyline,Javascript,Google Maps,Google Maps Api 3,Get,Google Polyline,我正在制作谷歌地图,该地图需要显示: KML(平面图) 多段线,每5秒从GET响应获取其坐标。 我希望多段线使用RESTful API提供的新坐标自我更新。 这是代码[更新]: var FlightPath1 = [] $(document).ready(function() { var BASE_URL = "https://its.navizon.com/api/v1/sites/" //Do not change this

我正在制作谷歌地图,该地图需要显示: KML(平面图) 多段线,每5秒从GET响应获取其坐标。 我希望多段线使用RESTful API提供的新坐标自我更新。 这是代码[更新]:

        var FlightPath1 = []
            $(document).ready(function() {
            var BASE_URL = "https://its.navizon.com/api/v1/sites/"  //Do not change this
            SITE_ID = "1001"  // Your site ID here
            MAC_add = "00:1E:8F:92:D0:56"  //Mac address of the device to track
            USERNAME = "demo@navizon.com"  // Your username
            PASSWORD = ""  // Your password
            var Path1=new google.maps.Polyline({
                path:FlightPath1,
                strokeColor:"#F020FF",
                strokeOpacity:0.8,
                strokeWeight:2
                });
// Send the request
            jQuery.support.cors = true;   // Enable cross-site scripting
function makeCall() {
    $.ajax({
        type: "GET",
        url: BASE_URL + SITE_ID + "/stations/" + MAC_add + "/",
        beforeSend: function(jqXHR) {
        jqXHR.setRequestHeader("Authorization", "Basic " + Base64.encode(USERNAME + ":" + PASSWORD));
        },

        success: function(jimmi) {
            // Output the results
            if (typeof jimmi === "string") {
                jimmi = JSON.parse(jimmi);
            }
            //Display the results
                FlightPath1.push("new google.maps.LatLng(" + jimmi.loc.lat + "," + jimmi.loc.lng + "),");
                var mapOptions = {
                                    zoom: 19,
                                    center: new google.maps.LatLng(jimmi.loc.lat,jimmi.loc.lng),
                                    mapTypeId: google.maps.MapTypeId.ROADMAP
                                };

                                map = new google.maps.Map(document.getElementById('map-canvas'),
                                mapOptions);

                                var SanDiegoKML = new google.maps.KmlLayer({
                                url: 'https://s3.amazonaws.com/navizon.its.fp/1001/05w0kyw829_a.kml'
                                });
                                SanDiegoKML.setMap(map);
                                google.maps.event.addDomListener(window, 'load', jimmi);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert('Error');
        }
    });
    window.setTimeout(makeCall, 5000); //run the script each 5000 milliseconds
}
makeCall();
})
但我什么也没发生。我也没有错误。 有人能帮我吗? 谢谢。

两个问题:

  • 必要的var
    Path1
    initialize()
    的内部和私有变量,因此超出了ajax success函数的范围,该函数位于完全不同的范围内

  • ajaxsuccess函数除了将从响应中派生的字符串推送到数组之外,什么都不做。这样做本身不会影响多段线

  • 先修复(1),然后修复(2)