2011-07-13 72 views

回答

4

W3C說明書中,第5.4節:

「速度屬性表示主機設備的當前速度的水平分量的大小並在每秒米指定...」

0

這裏是顯示MPH中速度的代碼:

var speedEl = document.getElementById('speed'); 
navigator.geolocation.watchPosition(function(geodata){ 
    var speed = geodata.coords.speed; 
    if(speed === null || speed === 0){ 
     speedEl.innerHTML = "You are standing still"; 
    }else{ 
     speedEl.innerHTML = (speed * 2.23693629) + "Mph"; 
    } 
},function(){ 
    speedEl.innerHTML = "Unable to determine speed :-("; 
}, {enableHighAccuracy: true});