How do I use the Android Geofencing API?
Asked Answered
X

5

21

I have been testing the new Google Play Geofencing service API.

I downloaded the sample code from the Android developers site. Next, I ran the example code on an Android device (Galaxy Note 2). I placed my office geo-position and radius to 10m, but when I walked to my office, nothing happened.

While running the sample code, one thing I have noticed is that when I am already inside the geofence range and then add the geofence to LocationClient, nothing happens.

I had already read LocationClient class documentation, and found the following paragraph:

In case network location provider is disabled by the user, the geofence service will stop updating, all registered geofences will be removed and an intent is generated by the provided pending intent. In this case, hasError(Intent) returns true and getErrorCode(Intent) returns GEOFENCE_NOT_AVAILABLE."

So I turned on WiFi, and was walking to my office (inside the geofence), and then I got notification "geofence entered".

I have the following questions:

  1. Does geofencing only work with WiFi enabled?

  2. Why doesn't the location provided by my 3G network work?

  3. Is this a bug in the sample code?

  4. Or is this my mistake?

Xavier answered 27/5, 2013 at 8:59 Comment(9)
Same here, I have seen that the geofences I declare only work when my device has wifi connection...If it's a bug, it's a pretty disturbing oneFrodeen
I am able to have geofencing triggered on 3g/4g/wifi but on 3g/4g I have to set my geofence radius much larger. As Milos suggested is correct. I also have wondered if anyone has noticed the lag time when setting this up? The lag being when you enter a geofence.. its not instant.Dollydolman
I am at the moment finding this sample project bit confusing. What is geo fence 1 and geo fence 2. Why do I have to enter lat, long and radius 2 times?Yuzik
NetworkLocationProvider doesn't mean only wifi, its a tringualtion of Wifi and cell tower. That's pretty awful that geofence api doesn't work if user has turned off the Network Location even if GPS is on (According to the documentation).Adao
Note that even when you do get a position it might be getting "filtered" such that it doesn't update in real. See my answer elsewhere in this thread.Ronnyronsard
please someone tell me that what values I need to put in geofence2 ? In geofence1 I am putting my current lat long. and I am getting only "Entering Geofence", notification. But when am walking more than 100 meters, still I am not getting any "Exiting Geofence" notification. I am using wifi but my device on data pack also. Please help meBaese
oddly enough google has pulled the tutorial that this sample went with (was here: developer.android.com/training/location/geofencing.html )Shopkeeper
@MuhammadBabar I'm facing problem with geofence , My geofence only work with data connection and some times it works with Wifi connection , and main thing If your sharing data with hotspot then it is not triggering the event. I dont know what happening , Please helpGuilder
@atishr this developer.android.com/reference/kotlin/android/location/… geofencing api from the LocationManager class is quite accurate though.Adao
R
5

If you only use cellular network, the location accuracy is lower, than the accuracy of wi-fi or gps (if you open Google Maps, the blue circle is estimation of your current position - if you only use 3GP, the circle can have radius of even hundreds of meters).

Last days I am working on an app using Geofences and I figured out the following: IMHO the geofence entry is triggered only if ALL this "location estimation circle" is inside the geofence radius, i.e. if there is 100 % chance that you entered the geofence. So it depends on how big radius you set. If you set only 10 metres, it will probably work only with GPS, never with 3GP. For 3GP you will have to set radius like 1000 metres.

Ragg answered 2/6, 2013 at 14:19 Comment(1)
Actually, the tests I made showed that the geofence trigger does not care about accuracy at all and unfortunately there doesn't seem to be any way to set if we want if or not..in my case cell-ID locations with 800-1500m accuracy are enough to trigger both enter and leave geofence events on a 200m geofence..As you probably guessed, I'm getting enter/leave events every 2 minutes without ever even moving..I wish we had better control and documentation of what to expect from this API because right now, it doesn't seem very usefulEndaendall
A
1

Wifi is used to help track your location. Using wifi signals and cell signals to triangulate your position is a more power efficient solution than having your GPS running constantly. Additionally it works in situations where GPS wouldn't such as heavy multipath areas and indoors.

Assignable answered 28/5, 2013 at 19:44 Comment(0)
S
1

in the case network condition you must Increase the radius at least 1000 M ,because using network provider to retrieving the current location,it take location from near by network tower.but in the case of GPS and wifi condition it works more accurate(1 M also).

Shovelhead answered 25/6, 2013 at 10:5 Comment(4)
when I test demo app for geofence provided by developer side,it will only send notification only when I on my wi-fi and set radius to 1000 M.In other case like network,gps and radius 1,10,100M I have tested its not sending notification.Do have any idea regarding it?Soldiery
i think in the case of network u should give the radius minimum 1000 M ,its work for me in the case of wifi You can give any radius like 1 ,10 ,100.Shovelhead
Yes..I can..but what should I have to do if I want to get notification when GPS/2G/3G is on?..If you have any demo will you please share itSoldiery
in case of 2G/3G give the radius to 1000 M minimum it will work in the case of sample provided by Developers siteShovelhead
R
1

I thought I'd share my results here. I too have developed a lab app that implements Google Play Services Location API and Geofence API. My results show that the location determination code has a sort of pathological inability to admit its mistakes. :)

When a button is pressed my app creates a geofence at the current location ("curLoc") returned by the location API with a 30 meter radius. On the screen I'm displaying the distance to the geofence center ("distToCenter") by calling curLoc.distanceTo(fenceLoc) and updating it roughly every second.

I start the app and wait until the accuracy stabilizes (normally at 10.0 meters), then press the button to create the fence. I get the "enter" event immediately. I clear the event and go for a walk and apparently enter a space-time anomaly. I walk down the block and around the corner, and the distToCenter value has only increased by about 4 meters. I go further until I'm about 300 meters from my house (judging by counting steps) and the dstToCenter gradually increases. The geofence exit event finally fires about 20 seconds AFTER the dstToCenter goes above 30 meters.

I wait to see where the distance stabilizes and it's about 150-ish meters. I turn around and head back home and the same extreme position lag occurs. I sit down at my desk while my wormhole self is still about 90 meters away. After about 40 seconds my doppleganger gets within the fence and after about 20 more seconds I get the enter event.

At this point I'm still somewhere on the front sidewalk (7.4 meters away), inching my way to the front door.

NOTE: The source was "fused" throughout although I did see the GPS status bar icon come on and flash for a few seconds after I'd lost connectivity to my WiFi. What's more, the accuracy never wavered from 10.0 meters.

LIARS!

:)

Ronnyronsard answered 1/8, 2014 at 5:2 Comment(0)
D
0

I tested sample geofence application, and if WiFi is Off it does not detect geofence events on version less than Android 4.3.

Android 4.3 and above works even WiFi is Off.

Danelledanete answered 18/3, 2014 at 23:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.