Name is Nilay
Name is Nilay

Reputation: 2783

Geofencing with only GPS does not work in android

I want to use Geofencing location API in my application to set certain Point of Interest. I have used this demo provided by google. I am able to run this demo when WIFI and location services both are on. But this doesn't seem to work when only GPS is turned on. I am not able to get GEOFENCE_TRANSITION_ENTER or GEOFENCE_TRANSITION_EXIT events for that. I have modified the expiration time to NEVER_EXPIRE, but still no luck. Can anyone point out what I am doing wrong ? TIA.

Edit: After following many sites, I finally managed to get the Geofence API working with this code. That is, Poll the GPS hardware on an interval without doing anything with the result. But now my question is that, is it the right way to do it ? Will google allow this once it's on Play store ? Please guide me on this topic.

Upvotes: 4

Views: 2778

Answers (3)

Nick Nock
Nick Nock

Reputation: 76

see - https://developer.android.com/training/location/geofencing.html#Troubleshooting

"On most devices, the geofence service uses only network location for geofence triggering." this may explains your problem with GPS only.

Upvotes: 1

Uncaught Exception
Uncaught Exception

Reputation: 2179

is it the right way to do it ?

Yes. Almost every developer I know who has used geofencing in his app and wants to get latest and accurate position resorts to this technique. The nature of geofencing kind of forces you to do this.

Will google allow this once it's on Play store ?

Absolutely yes!

Upvotes: 2

Marian Paździoch
Marian Paździoch

Reputation: 9093

Geofencing Api will not work if only GPS is set as Location Mode. When you set Location Mode to GPS ("Device only") all geofences are removed from Geofencing Api and you as a developer has to restore them after user changes Location Mode to something else. See also Error adding geofences in Android (status code 1000).

Upvotes: 0

Related Questions