Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug in Android Geofence Sample code? Can anyone please confirm?

I am not sure if this is a bug with the new Android GeoFence sample code or my understanding of what it is supposed to do is wrong. The sample app creates geofences but does not alert when geofence is breached. If anyone would like to give this a try and confirm, you can download the sample code from here :

https://developer.android.com/training/location/geofencing.html

This is what I was expecting the sample app to do :

  • Setup 2 different geofences. In my case, I picked 2 points a mile apart by entering their respective lat/long. I also set the radius to 250m .
  • I drove to each of those 2 locations one after another and I assumed a notification would popup indicating that the geofence has been breached.

In this case, no notifications nor any log messages were registered which means that "ReceiveTransitionsIntentService" never got called. One observation is that when I drive to the first location and then add a new geofence right at that location, the notification gets fired immediately, but any other location (geofence) I set and drive to, nothing happens.

Any idea why? Is my understanding correct about the sample app's functionality?

Do I need to do anything in addition to what is in the sample code to receive an alert when I breach the geofence while driving? Is geofence monitoring separate from creating geofences, what am I missing here?

Highly appreciate any input, We are very eager to use this in our app but right now we are stuck.

Thanks, Torri.

like image 419
Torri Veganas Avatar asked May 23 '13 12:05

Torri Veganas


People also ask

How does Geofencing work android?

Geofencing combines awareness of the user's current location with awareness of the user's proximity to locations that may be of interest. To mark a location of interest, you specify its latitude and longitude. To adjust the proximity for the location, you add a radius.

What is geofence error?

Essentially, the error is telling that you're dealing with a misbehaving app or app service that isn't collaborating well with GeoFencing.

How does Google Geofencing work?

The geofencing API allows you to define perimeters, also referred to as geofences, which surround the areas of interest. Your app gets a notification when the device crosses a geofence, which allows you to provide a useful experience when users are in the vicinity.


2 Answers

First of all, your understanding of the app's functionality is correct. Whenever you enter/leave one of your geofences it shows you that in a notification (it's always updating the same notification btw, so keep an eye out for it or you might miss one of the events).

Second, be careful because Geofence 1, by default, is only triggering ENTER events. So if you leave that geofence area after being inside it you won't get a notification for that! You can change this behavior in the creation of the mUIGeofence1 object on MainActivity.java.

Lastly, as with all things related to location, this API isn't perfect.. From my tests so far I have never seen it start up the GPS, so when outside it pretty much seems to rely on network locations which can easily not fall under a 500m radius geofence even if you're standing right in the middle of it. During one of the presentations at IO, Reto Meier mentioned that the API would be clever enough to handle battery drain the best way possible, so it would only turn on GPS when the user starts getting close to a geofence - which makes sense - but this never seems to happen unfortunately.

like image 89
rjam Avatar answered Oct 12 '22 00:10

rjam


The API will never "turn on" GPS. You have to start GPS yourself.

like image 39
Joe Malin Avatar answered Oct 12 '22 02:10

Joe Malin