为什么地理定位在移动浏览器和台式机上不起作用?

问题描述

我正在尝试使用HTML5地理位置来获取用户的位置。在桌面上当我授予访问权限2时,出现此错误:2:位于“ https://www.googleapis.com/”上的网络位置提供者:未收到任何响应。当我在手机上进行测试时,它不会询问访问问题和错误1:用户被拒绝地理位置定位

这是我的代码

successHandler(position) {
  console.log(position)
  alert(position.coords.latitude)
  alert(position.coords.longitude)
},errorHandler(errorObj) {
  alert(errorObj.code + ": " + errorObj.message);  
},getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(this.successHandler,this.errorHandler,{
      enableHighAccuracy: true,maximumAge: 10000,timeout: 10000
    })
  } else {
    alert("Geolocation is not supported by this browser.");
  }
}
created() {
  this.getLocation()
},

我在所有设备上都使用Google Chrome。

解决方法

  1. 要在Google Chrome浏览器上进行地理位置定位,必须与Google建立连接。因此,如果您所在的地区被禁止使用Google,那么它将无法提供位置服务。
  2. 就像其他人提到的那样,地理位置需要HTTPS。