【问题标题】:Google not revert currect lattitude and longitude of current position [duplicate]谷歌不恢复当前位置的当前纬度和经度[重复]
【发布时间】:2019-05-31 09:59:19
【问题描述】:

我想在 laravel 中构建定位我的功能。我正在使用此代码,但它发送的纬度和经度略有不同。

function getLocation() 
{
  var x = document.getElementById("lat_long");
   if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(showPosition);
  } else {
  x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) 
{
   var x = document.getElementById("lat_long");
   x.innerHTML = "Latitude: " + position.coords.latitude + 
   "<br>Longitude: " + position.coords.longitude; 
}

有没有替代品。这样我就可以提高我的成绩。

【问题讨论】:

  • 这是 Javascript 而不是 PHP/Laravel
  • 是的,但我使用的是 laravel php 框架
  • 浏览器地理位置的准确性取决于很多因素。它通常不会完全准确,这是意料之中的。
  • 您可能想查看stackoverflow.com/questions/16202077/… 并了解EnableHighAccuracy 标志。但除此之外,您没有任何问题,至少没有您指出的问题。地理位置并不总是完全准确的,尤其是在没有 GPS 的桌面上(就像在手机上一样)。这里没有什么要解决的。

标签: javascript php laravel-5 google-geocoder


【解决方案1】:

为了获得更高的准确性,您需要将 Options 对象设置为 enableHighAccuracy 为真。有关该功能的更多详细信息,您可以在此链接上查看 https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-16
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多