我正在使用Angular 6 PWA,我想要检查用户进入或离开特定区域时的位置。"geoFencing";
当用户在我的应用程序上时,它是有效的,但我想要的是即使在浏览器关闭的情况下也在后台执行它。
地理围栏的代码
var id, target, options;
function success(pos) {
var crd = pos.coords;
if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
console.log('Congratulations, you reached the target');
navigator.geolocation.clearWatch(id);
}
}
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
}
target = {
latitude : 0,
longitude: 0
};
options = {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 0
};
id = navigator.geolocation.watchPosition(success, error, options);发布于 2018-09-29 22:59:55
不幸的是,这在现有的web API中是不可能的。有一个w3c规范,但看起来它已经被抛弃了:
https://www.w3.org/TR/geofencing/
要获得这种功能,您必须构建一个本机应用程序。
发布于 2018-09-28 18:31:32
不可能。
当浏览器web应用移动到后台时,您将无法再访问位置信息。
也许可以考虑构建一个本机应用程序。
https://stackoverflow.com/questions/52552884
复制相似问题