-1
我想达到的目标 -绘制线 - 谷歌地图APIv3
我有2个变量 - 纬度经度&,无一不是在后台更新。我想根据正在更新的变量绘制一条线。
我在想什么 -
- 创建阵列的路径。
- 创建线。
- 更新使用的setInterval
代码中该行的路径 -
var poly;
function initialize() {
var Latitude
var Longitude
Latitude= {code that updates}
Longitude= {code that updates}
//create map
var mapOptions = {
zoom: 8,
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var path = [];
poly = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
poly.setMap(map);
var myVar = setInterval(function(){updateposition()},2000);
function updateposition(){
path.push(new google.maps.LatLng(Latitude,Longitude));
}
}
问题 - 没有线出现在所有:(
你需要更新的路径后更新折线(poly.setPath(路径))的路径属性。 – geocodezip
在我的情况下,我该怎么做? – satnam