2017-04-14 108 views
2

我创建了一个用来计算距离的应用程序。它通过保存一个起始位置并使用一个工作正常的逻辑来评估当前位置距离这个位置的距离。但问题是navigator.geolocation.getCurrentPosition()即使站在同一个点上也会返回不同的坐标,这会使坐标距离精确位置达到30米。任何人都可以建议我如何获得确切的坐标?为什么即使站在同一位置,navigator.geolocation.getCurrentPosition()也会返回不同的坐标?

回答

1

你试过enableHighAccuracytrue

var options = { 
    enableHighAccuracy: true, 
    timeout: 5000, 
    maximumAge: 0 
}; 

function success(pos) { 
    var crd = pos.coords; 

    console.log('Your current position is:'); 
    console.log(`Latitude : ${crd.latitude}`); 
    console.log(`Longitude: ${crd.longitude}`); 
    console.log(`More or less ${crd.accuracy} meters.`); 
}; 

function error(err) { 
    console.warn(`ERROR(${err.code}): ${err.message}`); 
}; 

navigator.geolocation.getCurrentPosition(success, error, options); 

来源:https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition

+0

感谢您的答复,我曾经尝试都enableHighAccuracy是真实的,以及假的,但它确实没有任何好处 –

相关问题