【发布时间】:2013-12-19 12:40:27
【问题描述】:
我想要达到的-
我有 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(path))。
-
我该怎么做?
标签: java javascript google-maps gps setinterval