简体   繁体   English

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

[英]why does geolocation not work on mobile browsers and desktop?

I am trying to get the location of the user with HTML5 geolocation.我正在尝试使用 HTML5 地理定位获取用户的位置。 On Desktop Gives this error when I grant access 2: Network location provider at 'https://www.googleapis.com/': No response received.在桌面上 当我授予访问权限 2 时出现此错误:“https://www.googleapis.com/”的网络位置提供商:未收到回复。 And when I test on a mobile phone, it does not ask the access question and error 1: User denied Geolocation而且我在手机上测试的时候没有问访问问题和error 1: User denied Geolocation

this is my code:这是我的代码:

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()
},

I am using Google Chrome on all devices.我在所有设备上都使用谷歌浏览器。

  1. Geolocation on Google Chrome requires connection with Google. Google Chrome 上的地理定位需要与 Google 连接。 As a result, if you are in a region where Google is banned, it cannot provide location service.因此,如果你在谷歌被禁止的地区,它就无法提供定位服务。
  2. As other guys mentioned, geolocation requires HTTPS.正如其他人提到的,地理定位需要 HTTPS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么地理定位不适用于移动浏览器? - Why does geolocation not work on mobile browsers? 地理定位代码适用于桌面浏览器,但不适用于移动设备 - Geolocation code working on desktop browsers but not on mobile devices 为什么滑块适用于桌面而不适用于移动设备? - Why does slider work on desktop but NOT on mobile? 为什么移动浏览器似乎提供了与台式机浏览器不同的Javascript Date()结果? - Why does mobile safari seem to give different Javascript Date() results from desktop browsers? 地理定位 API 在我的手机上无法使用,但在台式机上可以 - Geolocation API is not working on my mobile phone but on desktop does 如何创建适用于移动和桌面浏览器的平面图? - How to create floor plans that work nice with mobile and desktop browsers? BlogSpot 中的 JavaScript/Jquery 在移动浏览器中不起作用 - JavaScript/Jquery in BlogSpot does not work in mobile browsers 为什么我的 DIV 没有显示在移动浏览器中,而是显示在桌面浏览器中? - Why my DIV is not showing up in mobile browser but shows on desktop browsers? 为什么parseFloat在移动浏览器上返回整数? - Why does parseFloat return an integer on mobile browsers? 为什么单击功能在移动设备上无法在此SVG内运行,但在台式机上却可以运行? - Why does my click function not work inside of this SVG on mobile devices but it does on desktop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM