0

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?

Grigor
  • 4,139
  • 10
  • 41
  • 79
  • What makes you think that Geofence wouldn't work for your use case? – ianhanniballake Aug 17 '14 at 22:22
  • @ianhanniballake I just don't know how to do it using Geofence. I want to understand how it will work. – Grigor Aug 17 '14 at 22:29
  • So you've already read the [Geofence training](http://developer.android.com/training/location/geofencing.html) and looked at the parameters available when [building a Geofence request](http://developer.android.com/reference/com/google/android/gms/location/Geofence.Builder.html). What specifically don't you understand? – ianhanniballake Aug 17 '14 at 22:32
  • How will geofence trigger an event to hit my database, when user enters into the set geofence. – Grigor Aug 17 '14 at 22:42
  • @ianhanniballake actually, the geofence tutorial is very sophisticated and has many bugs. (That's what I read online.) – Grigor Aug 17 '14 at 22:44
  • 1
    If you read the tutorial (which, I agree, is more verbose than it needs to be), you'd have read the [Handling Geofence Transitions](http://developer.android.com/training/location/geofencing.html#HandleGeofenceTransitions) section, which details what happens when a Geofence is triggered. – ianhanniballake Aug 17 '14 at 22:46
  • Thanks for pointing that out. I will give it a third read. @ianhanniballake Sorry if any of my questions didn't make sense, only been 3 to 4 months since I've been developing Android. – Grigor Aug 17 '14 at 22:53
  • @ianhanniballake 1 more question, if you don't mind. What happens when the Geofence is built? Does it add to the list of geofences to track automatically or do I have to do that through LocationClient? – Grigor Aug 17 '14 at 23:01

1 Answers1

1

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.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443