Bug in Android Geofence Sample code? Can anyone please confirm?
Asked Answered
M

6

15

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.

Mitman answered 23/5, 2013 at 12:26 Comment(5)
I'm also having the same problem- I only receive a notification that the user is entering the geofence (upon creating it). Nothing happens after that- exiting, or re-entering the geofence.Trin
Torri - have you found a solution to this issue yet? I've been working on a sample app and by merging the Geofence sample with the new Location API (fused location provider) and refreshing the user position, I've been able (for the most part) to get the proper enter/exit transitions to occur. It falls short when running in the background/app not open, but when open, it was about 90% spot-on, even down to 10 meters with no wifi or cell coverage. If you are still having problems, I can share my sample code with you.Chauvin
@Chauvin - I am fecing same problem as Torri.will you please share your working code?Infiltration
@nitishpatel-give this a try-github.com/kyleparker/geofencesample. Built using the example app & I added a content provider, google maps, editor. Using "my location" icon to trigger the geofence event. Took this basic code & pulled into an existing app that uses code/functions from the MyTracks app. When recording the path, it gets frequent location updates, which in turn triggers the geofencing events. It works 99% of the time with good accuracy. BTW, this has a lot of extra, unnecessary code-was testing a few different things-didn't clean up afterward. Use at your own risk :)Chauvin
This is because new Geofencing Api rarely use GPS. I think it's useless to implement it.Radley
S
10

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.

Shellyshelman answered 27/5, 2013 at 10:4 Comment(2)
There was definitely some false advertising in the session... Because as you mentioned gps is never being activated which doesn't really make sense... API seems promising and is usable but there appears to still be many bugs. You sir get a +1 because of mentioning there is only Geofence.GEOFENCE_TRANSITION_ENTER on the fence one which was driving me crazy for like half an hour...Windblown
it would only turn on GPS when the user starts getting close to a geofence as far current implementation this conditions Never seems to be true as it keep getting location from wifi+cell tower which is too much inaccurate.Radley
V
2

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

Vanderpool answered 29/5, 2013 at 16:44 Comment(2)
I did have the gps, wifi, 4g turned on, but the sample code does not raise a notification. Anyone can give it a try since the sample code is available to download for free. I would appreciate if you can try it out and let me know if there is indeed a bug in the sample code.Mitman
Do you have evidence for this? According to @Rick's answer, the API is supposed to turn on the GPS as a user approaches a Geofence and this was confirmed by Reto Meier at I/O. I'm not saying it works properly (!) but your answer implies that you believe this isn't the intended behaviour of the API.Clasping
R
1

also make sure you have set your radius big enough. I woudl sugget making it 1000 just to see if it works. I'm still playing around with it but the sample code here does work fine:

How do I use the Android Geofencing API?

Rhodarhodamine answered 2/6, 2013 at 0:31 Comment(1)
I had set it to 1000 and it worked. May I know in which unit does it work? I mean meter or km or mile?Eusporangiate
E
1

Initially I thought the same. It is because the radius is in Meters, and I thought it would be in KMS / Miles. So I had entered very small values. Then after few experiments I found that out. Entered bigger values and it worked like charm on my Nexus 5

Eusporangiate answered 11/10, 2014 at 17:4 Comment(0)
Q
0

I tried the GeofenceDetection sample code and it is working. I am using only Wifi and GPS, and set my radius to be 15 meters. When i walked to the region, it is not immediately show the notification. After a few seconds, i got "enter" notification. Also, even if i am standing still in the region, sometimes i got notified that i am exiting the region. It makes the app feels like it's jumping around in and out of a region.

Quiche answered 27/6, 2013 at 18:40 Comment(0)
S
0

I wrote a test app that used both the Google Play Services Location and Geofence APIs. I used the location API to get current location at a 1-second rate. When I set my geofence I displayed the distance from current location to the geofence center, updated whenever the position updated.

Right after the geofence is set I get the entry event. I clear that event and go for a walk well outside the geofence radius. The distance displayed lags like crazy. It took about three minutes for the position to catch up to me. A similar lag happened on the way back home.

Pity Play Services is closed source, I'd love to understand the limits of their algorithm.

Serilda answered 1/8, 2014 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.