rps*_*ep2 33 javascript jquery geolocation cordova
即时通过phonegap构建应用程序,带有地理定位按钮.
如果用户第一次拒绝地理定位权限,当他们再次点击地理定位按钮时,如何再次请求权限?
我目前的代码结构是:
function getLocation() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, positionError);
} else {
hideLoadingDiv()
showError('Geolocation is not supported by this device')
}
}
function positionError() {
hideLoadingDiv()
showError('Geolocation is not enabled. Please enable to use this feature')
}
Run Code Online (Sandbox Code Playgroud)
gto*_*nie 29
你不能.
您唯一能做的就是在浏览器的设置中显示重新激活位置共享的说明(https://support.google.com/chrome/answer/142065?hl=zh-CN).
这样做的两种方法:
以下代码仅适用于 Chrome。
步骤: 1. 打开 Chrome 2. 打开控制台 3. 在控制台中复制
var allowGeoRecall = true
Run Code Online (Sandbox Code Playgroud)
4.在控制台中复制函数
function getLocation() {
console.log('getLocation was called')
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, positionError);
} else {
hideLoadingDiv()
console.log('Geolocation is not supported by this device')
}
}
function positionError() {
console.log('Geolocation is not enabled. Please enable to use this feature')
if(allowGeoRecall) getLocation()
}
function showPosition(){
console.log('posiiton accepted')
allowGeoRecall = false
}
Run Code Online (Sandbox Code Playgroud)
在控制台中运行该函数
获取位置()
运行后,您将被要求允许分享您的位置。如果您的回答是否定的,您将被再次询问,直到您同意为止。
提示:如果您的用户有否定的回应,请让他知道您为什么需要坐标。让他明白这一步对于 Web 应用程序的良好运行至关重要。
| 归档时间: |
|
| 查看次数: |
28014 次 |
| 最近记录: |