用户不允许地理位置 - 第二次通知用户 [英] user disallowed geolocation - notify user second time

查看:97
本文介绍了用户不允许地理位置 - 第二次通知用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当第一次尝试在iPhone上获取地理位置时,我拒绝了。
每隔一段时间我想获取位置(在另一次重新加载页面之前),我没有回应(没有错误,也没有成功):

  navigator.geolocation.getCurrentPosition(
function(location){
ig_location.lat = location.coords.latitude;
ig_location.lng = location.coords.longitude;
alert('got it!');
},
function(PositionError){
alert('failed!'+ PositionError.message);
}
);

每当我无法获取位置时,有没有办法通知用户?

(我不需要使用watchPosition ...)

解决方案

Geolocation API的设计使其不会在用户拒绝后重复请求会让用户感到厌烦。您可以重置设置应用中的位置警告,但这就是您可以做的所有事情。



一旦用户连续两次拒绝地理位置权限,API将假定他们



核心位置文档中的确切措辞:


如果用户拒绝您的应用程序使用位置服务,则此方法会报告 kCLErrorDenied 错误。收到这样的错误后,您应该停止位置服务。



When trying to get geolocation on iPhone the first time - I declined. Every other time I want to get the location (before another reload of the page) I get no response (no error and no success):

navigator.geolocation.getCurrentPosition(
    function (location) {
        ig_location.lat = location.coords.latitude;
        ig_location.lng = location.coords.longitude;
        alert('got it!');
    },
    function(PositionError) {
        alert('failed!' + PositionError.message);
    }
);

Is there a way to notify the user every time I fail to get the location?
(I do not need to use watchPosition...)

解决方案

The Geolocation API is designed so that it doesn't annoy the user with repeat requests after they decline. You can reset the location warnings from the settings app, but that's about all you can do.

Once the user declines geolocation permission twice in a row, the API will assume they don't want it and not ask again.

Exact wording from the Core Location documentation:

If the user denies your application’s use of the location service, this method reports a kCLErrorDenied error. Upon receiving such an error, you should stop the location service.

这篇关于用户不允许地理位置 - 第二次通知用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆