cowbell / cordova-plugin-geofence Goto Github PK
View Code? Open in Web Editor NEWGeofencing plugin for cordova
License: Apache License 2.0
Geofencing plugin for cordova
License: Apache License 2.0
Currently the plugin is not listed in the plugins list
greetings,
for Android, if geofences are registered with the OS then why do you need the permission "run at startup"?
[javac] Compiling 21 source files to Z:\temp\myApp2\platforms\android\ant-bu
ild\classes
[javac] Z:\temp\myApp2\platforms\android\src\com\cowbell\cordova\geofence\Ge
oNotificationNotifier.java:33: error: ')' expected
[javac] .setContentText(notification.getText());
[javac] ^
[javac] Z:\temp\myApp2\platforms\android\src\com\cowbell\cordova\geofence\No
tification.java:67: error: ';' expected
[javac] return new long[] {0}, vibrate);
[javac] ^
[javac] Z:\temp\myApp2\platforms\android\src\com\cowbell\cordova\geofence\No
tification.java:67: error: not a statement
[javac] return new long[] {0}, vibrate);
[javac] ^
[javac] Z:\temp\myApp2\platforms\android\src\com\cowbell\cordova\geofence\No
tification.java:67: error: ';' expected
[javac] return new long[] {0}, vibrate);
[javac] ^
[javac] 4 errors
hi,
Firstly thanks a ton for this useful plugin. I think I can put this to good use in one of the Apps. But me being new to Android / Java, have this quick question. I may also be needing to do a background geolocation update. So I was thinking that instead of having another service or plugin do a background geolocation update, can I use this plugin to update a remote server with it's location co-ordinates? If yes where exactly do you think I should fit in the code to post the latitude / longitude data.
And also does this run as as service? I mean even after a reboot will it start up automatically?
Thanks a ton,
M&M
Hi cowbell,
Please Guide me How to bind Geofence methods in MAP application....Am using Ionic frame works and AngularJS. But when calling those methods from My application there is no response.....I installed geofence Plugin.
Hi,
is it possible to redirect the user to a specific state, when he taps on a transition notification?
thx
I cloned this repo and deployed it to my android device.
When I click the (+) to add a geofence, the Obtaining current location...
screen pops up and it just hangs.
I have tried different settings combinations between the wifi and location services and none of them cause it to not hang.
It works fine when I run in the browser, but not on my android device.
Hi,
I noticed that when I start my app inside a fence, the receiveTransition
is not fired for that fence. I suppose there are some valid arguments for this behaviour, since there is no real transition happening. However, there are cases where it is desirable to notify the app when it is inside a fence on startup.
For iOS, I found this thread. I'm proposing the approach where a check on initialization is implemented. We could provide an argument to the initialize
method to toggle this behaviour. Let me know what you think.
Since I am only testing on iOS for now, I am not really aware of the behaviour on Android. I came accross the GEOFENCE_TRANSITION_DWELL transition type, but I am not entirely sure if that is what we are looking for. Anyone who knows more about this for Android or who is willing to test?
Please share your thoughts on this.
Should be possible to change vibration pattern for the notification. The best option will be a few predefined patterns and if it is possible setting custom pattern e.g. (1000 1000 1000) - vibrate 3 times each 1 sec long.
Hi,
I'd like to know if it'd be possible to not display a notification on received transitions.
If I don't pass a notification object to the geofence, it breaks on this line on iOS (I guess it does the same on other devices).
I'd like to ping a route when a transition occur, without the user being notified.
Also, is the callback executed when the app is closed/killed ?
Thanks in advance
Hi there,
I first tested adding a static geofence and it worked fine.
I then worked off a list of location.
I calculate the distance from the device location to each lat/long referenced in the list and get the 20 closest distance to me.
Once I have an array of 20 objects, I loop through each of them to add them as geofence but it doesn't work. I tried 1, 3, 5, 10. Any number makes the app freeze.
I took a step back and started thinking maybe my location array is wrong so I hardcoded basic lat/long following the static example that worked but no luck.
One question is:
Can I loop through geofence.addOrUpdate indefinitely passing new objects or can I only create one per geofenceService? I'm really confused as to why it is not working.
Any help or advice would be greatly appreciated.
Cheers
Hi, I've been trying to build my Cordova (+Ionic) project using this plugin on Android and iOS. Building and running on Android went smoothly, but failed on iOS. Here is what I've done so far:
cordova plugin add https://github.com/cowbell/cordova-plugin-geofence
ionic platform add ios
ionic emulate ios
The error occured:
Check dependencies
Swift is unavailable on iOS earlier than 7.0; please set IPHONEOS_DEPLOYMENT_TARGET to 7.0 or later (currently it is '6.0').
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Error: /Users/rasita.sa/Documents/myPhonegap/myProject/platforms/ios/cordova/run: Command failed with exit code 65
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:756:16)
at Process.ChildProcess._handle.onexit (child_process.js:823:5)
I also try adding and building iOS platform in the sample application, got the same result.
Cordova version: 3.6.3-0.2.13
Ionic version: 1.0.0-beta.13
Did I do something wrong?
Hey Tomasz,
thanks for the cool plugin. I was wondering if regions persist between relaunches as described here:
https://developer.apple.com/library/mac/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html
"In this case, the options dictionary passed to the application:didFinishLaunchingWithOptions: method of your app delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your app was launched because of a location-related event."
thanks a lot,
max
Would be nice to have an option, which removes active geofences automatically by setting an expiration time (e.g. minutes or timestamp).
So far, I have to loop several times through active geofences.
How do you keep your geofences up to date and save as much ressources as possible?
When clicked on Notification:
Hi,
Perhaps somewhat related to this issue, since I have to configure the IPHONEOS_DEPLOYMENT_TARGET manually (cordova version 4.2.0).
Anyway, after I manually set the parameter, the build is still failing. My impression is that some dependencies are missing for SQLITE. I did not install anything else than this plugin, but if I understood the documentation correctly it should work out of the box.
What am I missing? If some dependencies are needed, could this be added to the documentation?
Perhaps this should be set up as part of the hooked script, which is not executed correctly. How can I fix that?
Thanks
Hi there!
I have recognized an error, when this plugin is installed.
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
Is there a way to get rid of that error?
Great library man. However, relying in pure android geofencing seems inaccurate for radius less than 1000m (http://stackoverflow.com/questions/23708655/how-to-make-geo-fencing-alert-more-accurate-in-android).
In order to improve the accuracy and response time, I think the plugin can benefit from using hardware GPS reading as suggested on stackoverflow discussion above. I tested by creating other app - which is just an app containing a button to read GPS position. Before I pushed the button on this other app, the notification when I exit a geofence is not displayed. But after I activated the button and got reading, the plugin works and send notification.
When using TransitionType = 3 there is not way to identify if it was an 'entered' or 'exited' event that triggered the event. Could the 'geo' object be modified in some way to identify if it was an Enter or Exit transition that triggered the current transition call?
The only way to currently detect this is to create separate Enter and Exit geofences, which on iOS uses up 2 of the 20 allowed fences (instead of just 1).
Possibility to define date-time periods when the monitoring geofence should be active.
hello again, I have been testing this on Android for a few weeks now and it works perfectly.
but iOS is failing to build on Phonegap Build. I included in my config.xml to not do iOS6 (preference name="deployment-target" value="7.0") but it still fails to compile. error:
cordova-plugin-geofence/GeofencePlugin.swift:20:49: error: use of undeclared type 'CDVPlugin'
full build log here: https://www.dropbox.com/s/v6codigjsxgfe16/build.txt?dl=0
ps - I am using the npm version (https://www.npmjs.com/package/cordova-plugin-geofence)
It is working fine on 8.3 but not on 8.4
I'm getting pushback from the apple store about UIBackgroundModes location being required.
They say to use region monitoring (which you are doing).
Is there a reason this plugin requires background location?
It seems like RegionMonitoring is supposed to handle that.
Can you remove that as a dependency of this plugin?
Running on android 5.0 the function initialize unresponsive success or error and consequently does not work for me.
What could be wrong?
A small and simple part of my code:
function onDeviceReady(){
window.geofence.receiveTransition = function (geofences) {
geofences.forEach(function (geo) {
console.log('Geofence transition detected', geo);
$(document).find('.status').html('Geofence transition detected');
alert('Geofence transition detected' + geo.id);
});
};
try {
window.geofence.initialize(onSucessInit, onErrorInit);
}
catch(err) {
alert('Erro try ---' + err.message);
}
startAPP();
}
function onSucessInit(){
alert('OK init');
}
function onErrorInit(){
alert('Error init');
}
Adding this plugin prevents build on ios platform for my app. Arguments to path.join must be strings.
http://stackoverflow.com/questions/30581667/build-fails-after-adding-geofence-plugin
Hi, with the recent update of the core apple system that happened last night, it appears to me this plugin is no longer compatible. I'm getting build compile errors in Swift. Would love to help out but at present have no time so I'm passing this along. Please fix as soon as possible! :)
What I did to test this:
These errors are found in:
Plugins/json.swift
Plugins/SwiftData.swift
And your plugin, I replaced "as" to "as!" which fixes your issues apparently but it appears you are using libraries that are no longer compatible.
Thanks!
Hey,
I created a new ionic app and then added the cordova-plugin-geofence.
In my app.js inside my $ionicPlatform.ready(function() function I want to initialize geofence with
window.geofence.initialize();
But in my console it always says window.geofence is undefined. Can someone help me what I'm doing wrong. The plugin installation went without any errors.
Thanks
I have this error when building my project:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
This is my plugin list:
android.support.v4 21.0.1 "Android Support v4"
com.google.playservices 21.0.0 "Google Play Services for Android"
com.ionic.keyboard 1.0.4 "Keyboard"
com.phonegap.plugins.PushPlugin 2.4.0 "PushPlugin"
com.vladstirbu.cordova.promise 1.0.0 "Promise"
cordova-plugin-camera 1.1.0 "Camera"
cordova-plugin-crosswalk-webview 1.0.1-dev "Crosswalk WebView Engine"
cordova-plugin-file 2.0.0 "File"
cordova-plugin-file-transfer 1.1.0 "File Transfer"
cordova-plugin-geofence 0.4.0 "geofence"
cordova-plugin-geolocation 1.0.0 "Geolocation"
cordova-plugin-splashscreen 2.0.0 "Splashscreen"
cordova-plugin-whitelist 1.0.0 "Whitelist"
nl.x-services.plugins.socialsharing 4.3.19-dev "SocialSharing"
org.crosswalk.engine 0.0.1-dev "Crosswalk Engine"
I also use Ionic CLI for building.
In one of your recent commits of the plugin.xml file, you changed the ID of Android specific libraries to invalid IDs that do not exist in the plugin repository. Also, there is an issue with the declared uses-permission
tags not being included in the compiled AndroidManifest.xml, resulting in the plugin not being able to use the Android location services as well as the "boot completed" broadcast.
It would be nice if there were an event or callback for when the app is opened through the notification. 'onNotificationClick' or something like that.
Hi There,
More of a question than an issue. Any idea when you might be adding ios support?
thanks.
Hi all,
today our app has been rejected. They were complaining about the "App registers for location updates" in the required background modes in the info.plist. We have replied that we need that key for the geofence and they said: geo-fencing does not require persistent background location tracking.
This answer is a bit weird. Anyone has some ideas or has the same issue???
Thank you
Hi Tsubik,
On line 178 in GeofencePlugin.swift file geoNotification data set to .asDouble! creates this exception. If I comment out and force a literal double, it breaks somewhere else. This is happening trying to add or update a geofence.
Can you verify that this is also happening on your end?
Thanks,
After entering and exiting geofences for several times consecutively (around 10+ times), my app crashes with the following error:
08-13 11:36:21.507: E/AndroidRuntime(6849): FATAL EXCEPTION: IntentService[ReceiveTransitionsIntentService]
08-13 11:36:21.507: E/AndroidRuntime(6849): Process: com.myapp.geofenceapp, PID: 6849
08-13 11:36:21.507: E/AndroidRuntime(6849): java.lang.RuntimeException: Init failed
08-13 11:36:21.507: E/AndroidRuntime(6849): at android.media.ToneGenerator.native_setup(Native Method)
08-13 11:36:21.507: E/AndroidRuntime(6849): at android.media.ToneGenerator.<init>(ToneGenerator.java:746)
08-13 11:36:21.507: E/AndroidRuntime(6849): at com.cowbell.cordova.geofence.BeepHelper.<init>(BeepHelper.java:10)
08-13 11:36:21.507: E/AndroidRuntime(6849): at com.cowbell.cordova.geofence.GeoNotificationNotifier.<init>(GeoNotificationNotifier.java:23)
08-13 11:36:21.507: E/AndroidRuntime(6849): at com.cowbell.cordova.geofence.ReceiveTransitionsIntentService.onHandleIntent(ReceiveTransitionsIntentService.java:56)
08-13 11:36:21.507: E/AndroidRuntime(6849): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
08-13 11:36:21.507: E/AndroidRuntime(6849): at android.os.Handler.dispatchMessage(Handler.java:102)
08-13 11:36:21.507: E/AndroidRuntime(6849): at android.os.Looper.loop(Looper.java:135)
08-13 11:36:21.507: E/AndroidRuntime(6849): at android.os.HandlerThread.run(HandlerThread.java:61)
I tested this with Nexus 5 running Lockito app (location simulation app) which simulated driving along a street with 8 geofences on the side. I set transition type to both enter and exit. The first trip went smooth, but when I run the simulation again the app crashed in the background.
The issue is likely to be related to ToneGenerator being used repeatedly in the app without releasing media player resources.
When using this plugin with Phonegap Build, it fails during the compilation.
The following build commands failed:
CompileSwift normal arm64 /project/PGProject/Plugins/com.cowbell.cordova.geofence/GeofencePlugin.swift
CompileSwift normal arm64 /project/PGProject/Plugins/com.cowbell.cordova.geofence/SwiftData.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
I have absolutely no knowledge of Swift. @tsubik could you help me please ?
Possibility to add custom icon for notification
Resource icon
notification: { icon: "res://ic_launcher" }
Loading local icon
notification: { icon: "file://img/image.png" }
As in the title. Sometimes when detecting geofence transition message saying "the app had stopped working" appears. Problem occurs when the main app is closed.
@tsubik I've got the plugin working while the app is on in iOS7 & iOS8 but if the app is not open on iOS7 it doesn't get notifications when entering geofences. (haven't tested in 8).
Any thoughts?
Import google play services and google support library from third party plugin, to avoid crashes between diferent plugins dependencies.
Hi,
I'm having a problem on Android when a transition is received when the app is not already running in the background. If the app is running it's fine. The app process starts (Task Manager shows it has a 5MB footprint) but doesn't appear to load the CordovaWebView. Here's the log output:
D/GeofencePlugin(29512): ReceiveTransitionsIntentService - onHandleIntent
D/GeofencePlugin(29512): Geofence transition detected
D/GeofencePlugin(29512): Webview is null
I'm not sure if this is an issue with the plugin or the way I'm using it but I've tried fiddling with a number of things and haven't got any closer. It's working on iOS, so any tips on the Android side would be gratefully received.
Regards,
Tom
Is it possible to run some code when a user enters or exists a fence? For example I want to call a REST method which lets the server know what has happened. This can then be used for really cool things such as sending a push message to the user, etc etc.
For example:
window.geofence.addOrUpdate({
id: "69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb",
latitude: 50.2980049,
longitude: 18.6593152,
radius: 3000,
transitionType: TransitionType.ENTER,
notification: {
id: 1,
title: "Welcome in Gliwice",
text: "You just arrived to Gliwice city center.",
openAppOnClick: true
},
action: function(id, transitionType) {
// perform some code such as as calling a REST web service
}
}).then(function() {
console.log('Geofence successfully added');
}, function(reason) {
console.log('Adding geofence failed', reason);
})
I try to use the plugin with a IOS. Everything works except the receiveTransition callback.
Somehow the geofencepluginWebview is nil so the receiveTransition function in cordova never gets called. Any hints?
At this point, it always goes for the else branch
class func fireReceiveTransition(geoNotification: JSON) {
log("FIRE RECEIVE-TRANSIITON! ");
var mustBeArray = JSON
mustBeArray.append(geoNotification)
let js = "setTimeout('geofence.receiveTransition(" + mustBeArray.description + ")',0)";
if (GeofencePluginWebView != nil) {
GeofencePluginWebView!.stringByEvaluatingJavaScriptFromString(js);
log("Callback is called now ");
}
else {
log("GeofencePluginWebview is nil!");
}
}
@tsubik technical question.
When I am adding bulk geofences they all get added to the database but in iOS only the first 20 are monitored. 20 is the iOS limit.
Question is , is there a way of changing which ones are monitored without having to remove them all and only add in 20?
Say I have 40 locations added to the database but I only want to monitor the closest 20.
Thank you for your useful plugin. My goal is to display my app as a suggested app on the iOS 8 lock screen. Is it somehow possible to achieve this using your plugin? It should be possible with a geofence.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.