Coder Social home page Coder Social logo

ti.android.geofence's Introduction

Ti.Android.Geofence gittio

Appcelerator Android module wrapping Geofence functionalities

Google Geofence

Overview

This module adds support for using Geofence in Titanium Apps. It can monitor all geofence transitions and fire a local notification as well. You can customize the notification in order to fit your needs. This module works when the app is in foreground, background, closed, after phone restart, App data cleared and if location providers get changed.

Titanium SDK

Will work only with 8+

Download

Download the Ti.Android.Geofence module here.

Looking for an iOS solution?

Try this module.

How to use it

Just follow the Documentantion.

ti.android.geofence's People

Contributors

deckameron avatar m1ga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ti.android.geofence's Issues

old source

please update your source. its 9 months old & dists are 4 months old.

delay before ENTERED is triggered

I am seeing a delay of up to 2-3 minutes on entering a fence, before the entered event is triggered.
I have added in my own Ti.Geolocation event listener and can see the location changing as i move about (into a new fence), but the entered fences aren't triggered until much later.

Is this related to battery consumption considerations or as intended for some other reason?
Or potentially its just me seeing this and its device/connection related, although the geolocation events would indicate not.

Thanks (again)
Mathew

Set up

Hi I wondered if you would be kind enough to help me

Im using 7.0.1.GA

I am trying to use this module but everytime I add the example code for addGeoFences I get:

[WARN] : W/System.err: java.lang.NumberFormatException: Unable to convert null
[WARN] : W/System.err: at org.appcelerator.titanium.util.TiConvert.toInt(TiConvert.java:415)
[WARN] : W/System.err: at ti.android.geofence.GeofenceModule.addGeofences(GeofenceModule.java:391)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:936)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1159)
[WARN] : W/System.err: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:363)
[WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107)
[WARN] : W/System.err: at android.os.Looper.loop(Looper.java:207)
[WARN] : W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5728)
[WARN] : W/System.err: at java.lang.reflect.Method.invoke(Native Method)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
[ERROR] : TiExceptionHandler: (main) [11,8232] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [1,8233] - In undefined:256,16
[ERROR] : TiExceptionHandler: (main) [0,8233] - Message: Uncaught Unable to convert null
[ERROR] : TiExceptionHandler: (main) [0,8233] - Source: geofence.addGeofences({
[ERROR] : V8Exception: Exception occurred at undefined:256: Uncaught Unable to convert null
[ERROR] : V8Exception: Unable to convert null

I have used your full example also and get the same result.

The part I didn't understand (whihc may cause this) is the libaries required

Where do I put the libraries you outline?

Sorry these may be super simple questions but I am a bit of a noob:)

thank you very much in advance

Mock GPS app generating errors in app

Hi,

I am trying to fake GPS location using this
https://play.google.com/store/apps/details?id=com.incorporateapps.fakegps.fre, to test my app, I have also tried others fake gps apps with the same result. I have setup mock location app in settings and can successfully use it to fool StreetView, so it appears to be working ok. However when i try to use it with my ti app i get the following on repeat. And the app fails to pickup the locations.

Ti.android.geofence 1.0.7

Thanks

[INFO] : I/GeofenceModule BroadcastReceiver: (main) [40,63255] onReceive - OnRebootBroadcastReceiver for Geofence : android.location.PROVIDERS_CHANGED
[INFO] : I/GeofenceModule BroadcastReceiver: (main) [1,63256] PROVIDERS_CHANGED_ACTION
[ERROR] : E/GeofenceModule BroadcastReceiver: (main) [0,63256] java.lang.IllegalArgumentException: Receiver not registered: ti.android.geofence.OnRebootBroadcastReceiver@a2e8160
[INFO] : I/GeofenceModule BroadcastReceiver: (main) [27,63284] onReceive - OnRebootBroadcastReceiver for Geofence : android.location.MODE_CHANGED
[INFO] : I/GeofenceModule BroadcastReceiver: (main) [1,63285] MODE_CHANGED
[ERROR] : E/GeofenceModule BroadcastReceiver: (main) [1,63286] java.lang.IllegalArgumentException: Receiver not registered: ti.android.geofence.OnRebootBroadcastReceiver@982e6de
[INFO] : I/GeofenceModule BroadcastReceiver: (main) [5,63291] updateGeofencesAdded()
[INFO] : I/GeofenceModule BroadcastReceiver: (main) [0,63291] Added Geofences Successfully! It should be working...

hint for receiving events when app is closed

hi douglas, thanks for this module and happy new year to you.

you say in the description "This module works when the app is in foreground, background, closed, after phone restart,..."
but down in the events part you say "These events can only be monitored when your app is in foreground or in background. They will never fire when your app is closed because the instance of your application does not exist".

can you give me a hint how i can receive the events when the app is closed or has not started after last phone reboot? foreground and background are already working fine but receiving enter events when app is not running is very essential for us.

thanks for your help.

kind regards
alexander

Notifications are not received on Android in any app state.

Environment Details:

  • Ti SDK 7.5.0
  • Target API Level Android 28
  • Nokia 6.1 - Android 9

I am able to get the events but only when app is running in foreground or in background state, but not receiving any notifications in killed state. May be it's due to Android 8/9 OS as I tested it only on Android 9 and don't have lower OS version devices.

Here's the sample code I am using:

var geofence = require("ti.android.geofence");
var locationAllowed = false;

function checkPermissions(cb){
   if (Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS)) {
       locationAllowed = true;
       (cb != undefined) && cb();

   } else {
       Ti.API.warn('Location permissions not granted! Asking now...');
       Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
           locationAllowed = e.success;
           (cb != undefined) && cb();
       });
   }
}

function addFences(){
    geofence.addGeofences({
        clearExistingFences : false,
        fences : [
{
                "id" : "office",
                "latitude" : 28.41259,
                "longitude" : 77.0425996,
                "radius" : 500,
                "transitions" : [ geofence.GEOFENCE_TRANSITION_ENTER, geofence.GEOFENCE_TRANSITION_DWELL, geofence.GEOFENCE_TRANSITION_EXIT ],
                'dwellTime' : 5 * 60 * 1000,
                //Notification
                "title" : "Office Address",
                'message' : 'I am at office address now.',
                "accentColor" : "#00AEE6",
                'smallIcon' : 'push',
                "type" : geofence.TYPE_PLACE_FENCE,
                "showGooglePlaceBigImage" : true
            },
            {
                "id" : "huda_metro",
                "latitude" : 28.4615863,
                "longitude" : 77.062657,
                "radius" : 500,
                "transitions" : [ geofence.GEOFENCE_TRANSITION_ENTER, geofence.GEOFENCE_TRANSITION_DWELL, geofence.GEOFENCE_TRANSITION_EXIT ],
                'dwellTime' : 5 * 60 * 1000,
                //Notification
                "title" : "Huda City Centre",
                'message' : 'I am at Huda City Centre now.',
                "accentColor" : "#2AC635",
                'smallIcon' : 'push',
                "type" : geofence.TYPE_PLACE_FENCE,
                "showGooglePlaceBigImage" : true
            },
            {
                "id" : "home",
                "latitude" : 28.4947681,
                "longitude" : 77.158355,
                "radius" : 500,
                "transitions" : [ geofence.GEOFENCE_TRANSITION_ENTER, geofence.GEOFENCE_TRANSITION_DWELL, geofence.GEOFENCE_TRANSITION_EXIT ],
                'dwellTime' : 5 * 60 * 1000,
                //Notification
                "title" : "My Home",
                'message' : 'I am at HOME now.',
                "accentColor" : "#D52C7D",
                'smallIcon' : 'push',
                "type" : geofence.TYPE_PLACE_FENCE,
                "showGooglePlaceBigImage" : true
            }
        ]
    });

    startFencing();
}

function startFencing(){
    if (locationAllowed) {
        geofence.startMonitoring();
    }
}

function stopAllFencing(){
    geofence.clearExistingFences();
}

function stopMonitoring(){
    geofence.stopMonitoring();
}

geofence.addEventListener(geofence.ERROR, function(e){
    Ti.API.error("GEOFENCE ERROR");
    Ti.API.error(e.message);
});

geofence.addEventListener(geofence.ENTERED, function(e){
    alert("ENTERED");
    alert(JSON.stringify(e));
});

geofence.addEventListener(geofence.EXITED, function(e){
    alert("EXITED");
    alert(JSON.stringify(e));
});

geofence.addEventListener(geofence.DWELL, function(e){
    alert("DWELL");
    alert(JSON.stringify(e));
});

geofence.addEventListener(geofence.STARTED_MONITORING, function(e){
    alert("STARTED_MONITORING");
    alert("Monitoring...");
});

geofence.addEventListener(geofence.STOPPED_MONITORING, function(e){
    alert("STOPPED_MONITORING");
     alert("RIP!");
});

geofence.addEventListener(geofence.GEOFENCES_ADDED, function(e){
    alert("GEOFENCES_ADDED");
    alert("Ready to start monitoring!");
});

geofence.addEventListener(geofence.NOTIFICATION_CLICKED, function(e){
    alert("NOTIFICATION_CLICKED");
    alert(JSON.stringify(e));
});

checkPermissions(addFences);

I am testing the app nearby to physical location of first fence and whenever I spoof any other location to check exit or dwell events for any fence, I am not getting any events triggered up.

The only event triggered is ENTER and this is also fired only for the first location even if my current location is nearby to third geofence item.

I am spoofing the locations and getting correct co-ordinates for location updates in the Ti.Geolocation's location event.

Disabling notifications

Hi,

is there any way to disable notifications from arriving on enter/exit/dwell events?

Looking at the code seems that they always default to default text/message/images, but still curious is there any way to hack it.

Thanks

Context.startForegroundService() did not then call Service.startForeground

[ERROR] :  TiExceptionHandler: (main) [9051,29263]
Context.startForegroundService() did not then call Service.startForeground()
[ERROR] :  TiExceptionHandler:
[ERROR] :  TiExceptionHandler:
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2204)
[ERROR] :  TiExceptionHandler:
android.os.Handler.dispatchMessage(Handler.java:108)
[ERROR] :  TiExceptionHandler:     android.os.Looper.loop(Looper.java:166)
[ERROR] :  TiExceptionHandler:
android.app.ActivityThread.main(ActivityThread.java:7529)
[ERROR] :  TiExceptionHandler:     java.lang.reflect.Method.invoke(Native
Method)
[ERROR] :  TiExceptionHandler:
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
[ERROR] :  TiExceptionHandler:
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

It is an Android issue! Checkout here.

geofence.DWELL not triggering

Hi,

it seems that geofence.DWELL is not triggering whatever i do.
Here is relevant code:

for(var i in carouselCards) {
		if(carouselCards[i].cardWrapper.latitude !== null && carouselCards[i].cardWrapper.longitude !== null) {
		var newRegion = {
			"id": carouselCards[i].cardWrapper.id,
			"latitude": carouselCards[i].cardWrapper.latitude,
			"longitude": carouselCards[i].cardWrapper.longitude,
			"radius": 1000,
			"dwellTime" : (5000).toFixed(2),
			"transitions" : [
	                    	  geofence.GEOFENCE_TRANSITION_DWELL
		        ]
		}

		androidFences.push(newRegion);
	}
}

if(androidFences.length) {
	geofence.addGeofences({
		clearExistingFences: true,
		fences: androidFences
	});
	
        geofence.startMonitoring();
	geofence.addEventListener(geofence.DWELL, function(e){
	            Titanium.API.info(JSON.stringify(e));
	});
}

Fences array is populated, monitoring started but i can't get dwell callback to work.
Enter event works fine though.

Im using module version 1.0.2 and titanium sdk 7.4.0.GA. Also using Mock locations app to get desired behaviour.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.