user disallowed geolocation - notify user second time

可紊 提交于 2019-12-08 06:24:10

问题


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...)


回答1:


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.



来源:https://stackoverflow.com/questions/2471580/user-disallowed-geolocation-notify-user-second-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!