用户不允许的地理位置 - 第二次通知用户
当第一次尝试在 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...)
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...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Geolocation API 的设计宗旨是,在用户拒绝请求后,不会因重复请求而惹恼用户。您可以从设置应用程序重置位置警告,但这就是您所能做的。
一旦用户连续两次拒绝地理定位权限,API 将假定他们不想要该权限,并且不会再次询问。
核心位置文档中的确切措辞:
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: