簡體   English   中英

為什么地理定位在移動瀏覽器和桌面上不起作用?

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

我正在嘗試使用 HTML5 地理定位獲取用戶的位置。 在桌面上 當我授予訪問權限 2 時出現此錯誤:“https://www.googleapis.com/”的網絡位置提供商:未收到回復。 而且我在手機上測試的時候沒有問訪問問題和error 1: User denied Geolocation

這是我的代碼:

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

我在所有設備上都使用谷歌瀏覽器。

  1. Google Chrome 上的地理定位需要與 Google 連接。 因此,如果你在谷歌被禁止的地區,它就無法提供定位服務。
  2. 正如其他人提到的,地理定位需要 HTTPS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM