【发布时间】:2017-01-24 20:52:39
【问题描述】:
我在我的项目中使用 Ionic2 和 Angular2。当我安装 cordova-plugin-geofence (https://github.com/cowbell/cordova-plugin-geofence) 时。地理围栏配置如下:
App.ts
platform.ready().then(() => {
if (window.geofence === undefined) {
console.log('Geofence Plugin not found');
}else{
console.log('Geofence plugin found');
window.geofence.initialize();
const geofence = this.geofenceService.create({
longitude: -8.404015,
latitude: 43.339147,
});
this.geofenceService.addOrUpdate(geofence).then(function () {
console.log('Geofence successfully added');
}, function (reason) {
console.log('Adding geofence failed', reason);
});
}
});
主页.ts
window.geofence.onTransitionReceived = function (geofences) {
geofences.forEach(function (geo) {
console.log('Geofence transition detected', geo);
});
}
服务 geofence.service.ts 它被配置为 tsubik 的 ionic2 geofence 示例:https://github.com/tsubik/ionic2-geofence/blob/master/app/services/geofence-service.ts
在所有地理围栏配置过程中,控制台上都不会出现错误,但是当地理围栏转换发生时,方法 window.geofence.onTransitionReceived() 不会记录任何内容。
怎么了?谢谢!
【问题讨论】:
-
你必须定义一个半径和一个过渡类型。不要使半径接近,取1000或3000m之类的东西。
-
@Samuel Fraga Mateos,你收到通知了吗?即使我在这个插件上也面临问题。
-
@Joerg 我在默认地理围栏上定义了半径和过渡类型。当我创建一个新的地理围栏时,我只覆盖纬度和经度参数。
-
@Aish123 我根本没有收到通知。
标签: cordova angular typescript cordova-plugins ionic2