Search code examples
androidgeolocationandroid-geofence

Android: Mimicking Geofence with BroadcastReceiver and Location Updates


I am trying to build an App, that based on location queries the database to find scheduled tasks, given latitude, longitude and a radius.

I have found many answers, articles and libraries online that do similar things, but look very sophisticated and don't quite help me understand the concept.

I have previously been able to set up AlarmManager to fire tasks based on scheduled time, and I have thinking that I can set up Geofence to do the same, without me needing to create scripts that implement location updates. But it looks like this is not the case and I have to manually re-implement what could be a simple system wide support.

Ideal scenario: 1. Schedule a new task with lat, lng and radius. 2. Add it to Geofence, without worrying where the user currently is. 3. When user is in the area, find the row from database that this belongs to and do stuff with the db row.

But I think I have to go further than that to get this working.

Any ideas how I can achieve this?


Solution

  • The Geofence training is a good, if perhaps over-verbose example of the API. The core of it relies building Geofence requests and then adding them via LocationClient.addGeofences using a connected LocationClient. You then receive callbacks to the PendingIntent you passed in to addGeofences() as per Handling Geofence Transitions.