首页 > 解决方案 > 使用 HTML Geolocation API 的坐标错误

问题描述

我正在尝试使用 Chrome 作为浏览器在 Windows 10 上使用 HTML5 Geolocation API。我在获取正确的经度和纬度时遇到问题。我也尝试过使用一些 Web 应用程序,例如where-am-i.me,但它给出了相同的结果。只有谷歌提供正确的位置。我该如何解决这个问题,我们可以为此使用一些 Google API 吗?

enter code here
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
    $(".latitude").text(position.coords.latitude);
    $(".longitude").text(position.coords.longitude);
  showMap(position.coords.latitude, position.coords.longitude);
}

标签: htmlgeolocation

解决方案


推荐阅读