Javascript JS:如何制作动态谷歌地图多段线?
我正在制作谷歌地图,该地图需要显示: KML(平面图) 多段线,每5秒从GET响应获取其坐标。 我希望多段线使用RESTful API提供的新坐标自我更新。 这是代码[更新]: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
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();
})
但我什么也没发生。我也没有错误。
有人能帮我吗?
谢谢。两个问题:
Path1
是initialize()
的内部和私有变量,因此超出了ajax success函数的范围,该函数位于完全不同的范围内