Hello to all,
I’m really going crazy: I have to use the geofence plugin and I have to check more points, but the APP, when it is run on a smartphone, closes unexpectedly.
The thing I don’t understand is that, if I use only one point, the APP works correctly and it signals the notification when I approach the point. If instead I put 2 or more points the APP closes.
Here is the code I use:
import { Component, OnInit } from '@angular/core';
import { NavController, Platform } from '@ionic/angular';
import { Geofence } from '@ionic-native/geofence/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
constructor(public navCtrl: NavController, private platform: Platform, private geofence: Geofence) {
this.geofence.initialize().then(
// resolved promise does not return a value
() => console.log('Geofence Plugin Ready'),
(err) => console.log(err)
)
} //end constructor
ngOnInit() {
this.addGeofence();
}
private addGeofence() {
let fences = [{
id: 'Posizione_1',
latitude: 40.647220484321906,
longitude: 17.51329209037444,
radius: 50,
transitionType: 3,
notification: {
id: 111111111,
title: 'point 1 ',
text: 'radius 50 m',
openAppOnClick: true
}
},
{
id: 'Posizione_2',
latitude: 40.6450801,
longitude: 17.5189106,
radius: 1000,
transitionType: 3,
notification: {
id: 222222222,
title: 'point 2',
text: '1000 m radius',
openAppOnClick: true
}
},
{
id: 'Posizione_3',
latitude: 40.6465148,
longitude: 17.5140012,
radius: 10,
transitionType: 3,
notification: {
id: 333333333,
title: 'point 3',
text: '10 m radius',
openAppOnClick: true
}
},
{
id: 'Posizione_4',
latitude: 40.647306818872195,
longitude: 17.513850553571178,
radius: 50,
transitionType: 3,
notification: {
id: 4444444444,
title: 'point 4',
text: '50 m radius',
openAppOnClick: true
}
}
]
this.geofence.addOrUpdate(fences).then(
() => console.log('Geofence added'),
(err) => console.log(err)
);
}
} //end export class HomePage
I can’t understand where I’m wrong.
Thank you