1
我有一個方法getSpeed(),它定期計算兩個LatLng點之間的行進速度。目前我只是將結果輸出到控制檯,想知道如何將它輸出到我的網頁上的文本框/提要?使用javascript定期更新文本框
//retrieve information from database
downloadUrl("Map.php", function(data){
var xml = data.responseXML;
var allPoints = Array();
var markers = xml.documentElement.getElementsByTagName("marker");
for(var i = 0; i<markers.length; i++){
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
allPoints[i] = point;
}
for(var i = 1; i <allPoints.length; i++){
var distance = google.maps.geometry.spherical.computeDistanceBetween(
allPoints[i], allPoints[i-1]);
var speed = ((distance/1000)*60);
console.log(distance.toFixed(2)+'m at a speed of '+speed.toFixed(2)+'km/h');
if(speed < 8){
console.log('WARNING: SPEED IS LOW!');
}
}
});
}
我也有一個div定義如下,我正在找我的文本框中使用...
<div id="log" style="display: inline-block; margin-top: 100px; border: solid; border-color: black; border-width: 1px; width: 500px; height: 500px;" ></div>