【发布时间】:2016-10-11 21:47:56
【问题描述】:
我有一个由按钮单击触发的功能,用于检查地理位置。当地理位置处于打开状态时,它可以在手机上正常工作,而在关闭时,会按预期显示一条消息。当首先关闭手机的位置服务,单击按钮时出现问题(消息弹出,如预期的那样),然后如果用户在应用程序仍处于打开状态时重新打开位置服务,再次单击按钮,仍然相同弹出“无定位服务”消息。
有没有办法在每次点击按钮时检查手机的定位服务是打开还是关闭?在 Android 和 IOS 上获得相同的结果。
代码:
$(document).ready(function () {
$('#smallScreenGeolocate').on('click', function(){
getCurrentLocation();
});
});
function getCurrentLocation () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(addGeolocationMarker, locationError);
return true;
}
else {
alert("Browser doesn't support Geolocation. Visit http://caniuse.com to discover browser support for the Geolocation API.");
return false;
}
}
【问题讨论】:
-
没有人吗?我找不到任何东西来解决这个问题......似乎很奇怪,当 web 应用程序打开时我无法检测到地理定位是否已打开或关闭......?
-
我们在谈论某种框架吗?像 phonegap、cordova、xamarin 还是一个简单的 Web 应用程序?
-
如果您刷新页面(位置处于活动状态),那么可以访问位置详细信息吗?
-
@ddb 是的,.. 我实际上并没有为 webapp 开发包装器,但我相信他们正在使用 xamarin ......但我有 webapp 本身的问题;我需要刷新页面才能检测到地理位置。
标签: android ios events geolocation location-services