完成地理围栏后,我有应用程序,我能够完美地收到通知。
我的目标是在到达半径时动态获取通知。
现在,当我添加地理围栏 addorupdate 功能时,如果我需要再次获得另一个通知,那么我想再次添加。
取而代之的是,我可以通过任何方式观看我的纬度和经度背景,而无需一次又一次地添加。
这是我的代码
lat
long
constructor(public navCtrl: NavController, private geofence: Geofence, private geolocation: Geolocation) {
this.geolocation.getCurrentPosition().then((resp) => {
// resp.coords.latitude
// resp.coords.longitude
console.log(resp);
console.log("invoking the geolocation success");
this.lat = resp.coords.latitude;
this.long = resp.coords.longitude;
console.log(this.lat);
console.log(this.long);
this.addGeofence();
}).catch((error) => {
console.log('Error getting location', error);
});
console.log(this.lat);
console.log(this.long);
// initialize the plugin
geofence.initialize().then(
// resolved promise does not return a value
(success) => {
console.log(success);
console.log('Geofence Plugin Ready')
},
(err) => {
console.log(err);
console.log(err)
})
}
private addGeofence() {
//options describing geofence
let fence = {
id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb', //any unique ID
latitude: this.lat, //center of geofence radius
longitude: this.long,
radius: 50, //radius to edge of geofence in meters
transitionType: 3, //see 'Transition Types' below
notification: { //notification settings
id: 1, //any unique ID
title: 'You crossed bangalore', //notification title
text: 'You just arrived to bangalore.', //notification body
openAppOnClick: true //open app when notification is tapped
}
}
this.geolocation.getCurrentPosition().then((resp) => {
// resp.coords.latitude
// resp.coords.longitude
this.lat = resp.coords.latitude;
this.long = resp.coords.longitude;
}).catch((error) => {
console.log('Error getting location', error);
});
console.log(fence);
this.geofence.addOrUpdate(fence).then(
(success) => {
console.log(success);
console.log('Geofence added')
},
(err) => {
console.log(err);
console.log('Geofence failed to add')
});
}
添加地理围栏后,如何每次动态获取通知?