Search code examples
androidcordovacross-compilingphonegapgeofencing

Phonegap Geofencing plugin


Someone else got any phonegap geofencing plugin working?? I can't even install the ones I've found and those are only cordova plugins, not really phonegap. I though it should work but it does not.

Edit1:Watchposition is not an option beacause it does not work on non https, so a webview in file:// protocol certainly will not help on that.

Edit2: I need something to work in background while the app is in background, to stay running and get the coordinates of the geolocation.


Solution

  • I've made cordova-plugin-geofence work on a Phonegap project:

    Steps I made:

    Install Phonegap CLI

    npm install -g phonegap
    

    create a Phonegap CLI project

    phonegap create geofenceTest com.test.geofence geofenceTest
    

    Added Android 7.0.0 platform with

    phonegap platform add android@7.0.0
    

    (you can also add 6.4.0, but the default one doesn't work if you have latest Android SDK tools)

    Added the plugin with

    phonegap plugin add cordova-plugin-geofence
    

    In config.xml change this line (it had 14, but 16 is needed for latest Cordova)

    <preference name="android-minSdkVersion" value="16" />
    

    In index.js I added this in line 48

    window.geofence.initialize(function(){alert('init ok');}, function(){alert('init error');});
    

    Ran the app with:

    phonegap run android --device
    

    It asked for permissions and got the init ok alert

    All the Cordova plugins are Phonegap plugins, Phonegap apps are Cordova apps