什么是错误“权限已撤销”

问题描述 投票:0回答:1

我有一些像这样的代码用于获取用户位置 getLocaiton 是一个 onclick 侦听器:

function getLocation() {

if (navigator.geolocation) {

    navigator.geolocation.getCurrentPosition(setLocation, errorLocation);

   } else {
alert('error')
}
}
 let errorLocation = (error) => {
    console.log(error)
}
let setLocation = (location) => {
 try {
   console.log('ok')
   console.log(location.coords)
    } catch (e) {

    }
    }

我在 errorLocation() 函数中得到了这个错误

The permission was revoked

javascript geolocation
1个回答
0
投票

您可能会遇到

PERMISSION_DENIED
错误,因为您拒绝了位置访问。

获取地理位置信息失败,因为该页面没有必要的权限,例如因为它被权限策略

阻止

尝试启用它:

© www.soinside.com 2019 - 2024. All rights reserved.