Every time I run this code on my phone, it first displays
Module cordova-plugin-geofence.TransitionType does not exist
and then when I close the message and try to run the app anyway, it displays
[object PositionError]
Here is the code: (I have commented some snippets because not sure if it is right)
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';
import { Geofence } from '@ionic-native/geofence';
import { SMS } from '@ionic-native/sms';
import { ActivePage } from '../active/active';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
radius: number = 100;
error: any;
success: any;
constructor(public navCtrl: NavController, public geofence:Geofence, public geolocation: Geolocation, private SMS: SMS) {
document.addEventListener('deviceready', function () {
// window.geofence is now available
this.geofence.initialize().then(function () {
console.log("Successful initialization");
}, function (error) {
console.log("Error", error);
});
}, false);
/*
this.platform.ready().then(() => {
geofence.initialize().then(
() => console.log('Geofence Plugin Ready'),
(err) => console.log('error is happening here')
);
});
*/
}
setGeofence(value: number) {
this.geolocation.getCurrentPosition({
enableHighAccuracy: true
}).then((resp) => {
var longitude = resp.coords.longitude;
var latitude = resp.coords.latitude;
var radius = value;
let fence = {
id: "myGeofenceID1",
latitude: latitude,
longitude: longitude,
radius: radius,
TransitionType: 2, //see 'Transition Types' below
}
this.geofence.addOrUpdate(fence).then(
() => this.success = true,
(err) => this.error = "Failed to add or update the fence."
);
/* this.geofence.onTransitionReceived().subscribe(resp => {
this.SMS.send('+918277628369', 'The person has left');
});
*/
/* this.geofence.onTransitionReceived().subscribe( res =>{
/*res.forEach(function(geo) {
console.log(geo);
});
this.SMS.send('+918277628369', 'The senior citizen under your charge has left the house! Please ensure they are safe.');
},
(err) => console.log(err),
() => console.log("done !")
);
this.navCtrl.push(ActivePage);
*/
var phnum = document.getElementsByName("phnumber")
this.geofence.onTransitionReceived().subscribe( res =>{
res.forEach(function(geo) {
console.log(geo);
this.SMS.send(phnum, 'The person has left');
});
},
(err) => console.log(err),
() => console.log("done !")
);
}).catch((error) => {
this.error = error;
console.log(error);
});
}
}
Thanks for your help!
Edit: Here are screenshots of the errors.