I am trying to use geofencing in one of my Ionic-3 apps. After floolwing the instructions in https://ionicframework.com/docs/native/geofence/, I modified my app.components.ts that now looks like this:
import { Geofence } from ‘@ionic-native/geofence’;
@Component({ templateUrl: ‘app.html’ }) export class MyApp {
constructor(private geofence: Geofence) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this.startGeofence();
});
this.pages = [
]; }startGeofence() {
// initialize the plugin
this.geofence.initialize().then(
// resolved promise does not return a value
() => {
console.log(‘Geofence Plugin Ready’);
this.addGeofence();
},
(err) => {
console.log(‘Geofence Plugin failed’);
console.log(err);
}
) }private addGeofence() {
this.geofence.removeAll();
//options describing geofencelet fence = { id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acab', //any unique ID latitude: 41.2713354, //center of geofence radius longitude: 18.6108311, radius: 20, //radius to edge of geofence in meters transitionType: 3, //see 'Transition Types' below notification: { //notification settings id: 3, //any unique ID title: 'Geofencing', //notification title text: 'my home', //notification body openAppOnClick: true //open app when notification is tapped } } this.geofence.addOrUpdate(fence).then( () => console.log('Geofence added'), (err) => console.log('Geofence failed to add') ); this.geofence.onTransitionReceived().subscribe(resp => { resp.forEach(function (geo) { console.log("Geofence transition detected", geo); }); console.log("geofence on transition recieved", resp); alert(JSON.stringify(resp)); }); } }
In the console log I have the following messages:
deviceready has not fired after 5 seconds. Ionic Native: deviceready
event fired after 4964 ms Geofence Plugin Ready Geofence added
those show a correct initialization of the plugin, but, after that, nothing happens, the onTransitionReceived is never called.
My package.json:
{ “name”: “ClientIonicProject”, “version”: “0.0.1”, “author”:
“Ionic Framework”, “homepage”: “http://ionicframework.com/”,
“private”: true, “scripts”: {
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build”,
“lint”: “ionic-app-scripts lint”,
“ionic:build”: “ionic-app-scripts build”,
“ionic:serve”: “ionic-app-scripts serve” }, “dependencies”: {
“@angular/common”: “^5.0.1”,
“@angular/compiler”: “^5.0.1”,
“@angular/compiler-cli”: “^5.0.1”,
“@angular/core”: “^5.0.1”,
“@angular/forms”: “^5.0.1”,
“@angular/http”: “^5.0.1”,
“@angular/platform-browser”: “^5.0.1”,
“@angular/platform-browser-dynamic”: “^5.0.1”,
“@ionic-native/app-version”: “^4.4.0”,
“@ionic-native/core”: “4.3.3”,
“@ionic-native/geofence”: “^4.7.0”,
“@ionic-native/geolocation”: “^4.4.0”,
“@ionic-native/http”: “^4.4.0”,
“@ionic-native/in-app-browser”: “^4.4.0”,
“@ionic-native/launch-navigator”: “^4.4.0”,
“@ionic-native/network”: “^4.5.2”,
“@ionic-native/splash-screen”: “4.3.3”,
“@ionic-native/status-bar”: “4.3.3”,
“@ionic-native/text-to-speech”: “^4.4.0”,
“@ionic/storage”: “^2.1.3”,
“@ngx-translate/core”: “^8.0.0”,
“@ngx-translate/http-loader”: “^2.0.0”,
“cordova-android”: “6.3.0”,
“cordova-plugin-actionsheet”: “^2.3.3”,
“cordova-plugin-add-swift-support”: “^1.6.0”,
“cordova-plugin-advanced-http”: “^1.11.1”,
“cordova-plugin-app-version”: “^0.1.9”,
“cordova-plugin-compat”: “^1.2.0”,
“cordova-plugin-device”: “^1.1.4”,
“cordova-plugin-dialogs”: “^2.0.1”,
“cordova-plugin-file”: “^6.0.1”,
“cordova-plugin-geofence”: “^0.7.0”,
“cordova-plugin-geolocation”: “^3.0.0”,
“cordova-plugin-inappbrowser”: “^1.7.2”,
“cordova-plugin-ionic”: “^3.1.3”,
“cordova-plugin-ionic-webview”: “^1.2.1”,
“cordova-plugin-network-information”: “^1.3.4”,
“cordova-plugin-splashscreen”: “^5.0.2”,
“cordova-plugin-statusbar”: “^2.4.2”,
“cordova-plugin-tts”: “^0.2.3”,
“cordova-plugin-whitelist”: “^1.3.1”,
“cordova-sqlite-storage”: “^2.3.1”,
“es6-promise-plugin”: “^4.2.2”,
“ionic-angular”: “3.9.2”,
“ionic-plugin-keyboard”: “^2.2.1”,
“ionicons”: “3.0.0”,
“rxjs”: “5.5.2”,
“sw-toolbox”: “3.6.0”,
“uk.co.workingedge.phonegap.plugin.launchnavigator”: “^4.2.0”,
“zone.js”: “0.8.18” }, “devDependencies”: {
“@ionic/app-scripts”: “3.1.0”,
“typescript”: “2.4.2” }, “description”: “An Ionic project”, “cordova”: {
“plugins”: {
“cordova-plugin-tts”: {},
“cordova-plugin-app-version”: {},
“cordova-plugin-geolocation”: {
“GEOLOCATION_USAGE_DESCRIPTION”: “To locate you”
},
“cordova-plugin-inappbrowser”: {},
“uk.co.workingedge.phonegap.plugin.launchnavigator”: {},
“cordova-plugin-advanced-http”: {},
“ionic-plugin-keyboard”: {},
“cordova-plugin-whitelist”: {},
“cordova-plugin-device”: {},
“cordova-plugin-ionic-webview”: {},
“cordova-plugin-network-information”: {},
“cordova-sqlite-storage”: {},
“cordova-plugin-geofence”: {},
“cordova-plugin-add-swift-support”: {},
“cordova-plugin-statusbar”: {},
“cordova-plugin-splashscreen”: {}
},
“platforms”: [
“android”
] } }
ionic info:
cli packages: (C:\Users\francesco\AppData\Roaming\npm\node_modules)
@ionic/cli-utils : 1.19.2 ionic (Ionic CLI) : 3.20.0
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
@ionic/app-scripts : 3.1.0 Cordova Platforms : android 6.3.0 Ionic Framework : ionic-angular 3.9.2
System:
Android SDK Tools : 26.1.1 Node : v6.10.3 npm : 6.0.0 OS : Windows 10
Environment Variables:
ANDROID_HOME : D:\e\programmi_esterni\Android\android-sdk
Misc:
backend : legacy
Suggestions?