开箱即用的浏览器地理定位比生产网站稍微不那么准确

Out of the box browser Geolocation is slightly less accurate then production websites

本文关键字:网站 浏览器 定位      更新时间:2023-09-26

我正在笔记本电脑上查看我的地理位置。

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var lat = position.coords.latitude;
      var lon1 = position.coords.longitude;
   });
}

lat和lon给出的输出与相同浏览器在http://whereamirightnow.com/

这样的站点上输出的输出略有不同。

他们是在使用谷歌库来提高准确性还是怎么的?

事实证明,使用这种方法可以使我获得比其他站点更精确的经度和纬度。看起来是传单在引擎盖下做的,这让我很困惑。

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);
相关文章: