if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
console.log(position);
this.isLocationEnabled = true;
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
});
}
如果我禁用位置访问然后启用位置访问,那么问题就出现在浏览器中,因此尽管给出了访问权限,但第二次我还是收到了此错误
有什么解决办法吗
如果提供位置访问权限,它应该返回位置。但一旦我在浏览器中错误地禁用然后启用位置,它就会给我权限被撤销
您应该通过权限检查来结束此调用
navigator.permissions.query({ name: "geolocation" }).then((result) => {
if (result.state === "granted") {
// OK
} else if (result.state === "prompt") {
} else {
// denied
});