-2

My requirement:

Area around the Path(Route) is having some important places(quantity is approx. 50). When user is moving on the path, and reach to the nearest place(e.g. A), I need to perform some task particular to that place(e.g. A).

Currently, I am creating geofences for all the required places at the same time but having doubt about the battery consumption.

Is there any way to minimize the battery consumption? If yes, then please help. Any help or guidance will be well appreciated.

Note: User can enter to the route from start/end/middle of the route.

abhishek kumar gupta
  • 1,915
  • 6
  • 27
  • 50
  • Please post some code. If we don't know how you use the LocationClient etc., we can't help you. – tknell Jun 18 '14 at 14:47
  • Hi tknell, thanks for the reply. I have implemented in the same way given in the sample code provided by google (means I am connecting LocationClient for adding geofence, after getting onAddGeofencesResult() callback, I am disconnecting LocationClient. Same for the case of removing Geofence). I am having doubt about battery consumption when large number of geofences are active at the same time. – abhishek kumar gupta Jun 19 '14 at 05:26
  • Do you also request location updates from the LocationClient yourself, or just use the geofences? – tknell Jun 19 '14 at 08:35

1 Answers1

1

Here is one option:

  1. Run each point through an algorithm to determine the distance from the point to the user.
      For example lets say the user is at X(0),Y(0) run the root of (Xn - X(0))2 + (Yn - Y(0))2

  2. Assign the distance as a property of the geofence.

  3. Sort an array of the geofences for the new property.

  4. Add the 10 closest (or whatever number seems reasonable based on the distance of the path and proximity of the geofences with one another) regions to a new array.

  5. Register those 10 (or so) regions.

  6. Record the last location at which this process was done and compare it with the users current location. If the user travels a certain distance than begin the process over again.

Especially with the simple math operators this is much easier on the OS than searching for 50 regions simultaneously.

cgauss
  • 314
  • 2
  • 14