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.

Torri Veganas
  • 281
  • 1
  • 3
  • 12
  • 1
    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. – jimmyC Jul 08 '13 at 18:26
  • 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. – Kyle Jul 18 '13 at 13:56
  • 1
    @Kyle - I am fecing same problem as Torri.will you please share your working code? – Nitish Patel Sep 23 '13 at 09:31
  • @nitishpatel-give this a try-https://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 :) – Kyle Sep 24 '13 at 14:53
  • This is because new `Geofencing Api` rarely use GPS. I think it's useless to implement it. – Muhammad Babar Jun 05 '14 at 13:13

6 Answers6

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.

rjam
  • 577
  • 6
  • 19
  • 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... – Igor Čordaš Aug 30 '13 at 16:11
  • `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. – Muhammad Babar Jun 05 '14 at 13:16
2

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

Joe Malin
  • 8,621
  • 1
  • 23
  • 18
  • 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. – Torri Veganas May 30 '13 at 01:20
  • 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. – Carlos P Oct 23 '13 at 10:52
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?

Community
  • 1
  • 1
reidisaki
  • 1,525
  • 16
  • 29
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

Bala Vishnu
  • 2,588
  • 23
  • 20
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.

ogramus
  • 21
  • 10
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.

William T. Mallard
  • 1,562
  • 2
  • 25
  • 33