Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Geofencing

I've gone through the tutorial for Geofencing and I have question in mind.

Does geofencing require you to continuously monitor the user's location ?

Or will the LocationClient to which you add the Geofence automatically trigger when a transition has orccured ?

This might seem like an obvious question, but the tutorial never mentioned anything about requesting location updates from the location manager.

like image 620
Traxex1909 Avatar asked Jan 23 '14 11:01

Traxex1909


2 Answers

Hi it depends on the requirement.The Location tracking in the application can be implemented in following ways depending on the particular requirement. 1. Request one shot location of device wherever needed If app demands requesting device’s current location on screen say some API needs lat-long as input or need to use lat-long natively to display some info about current location of screen, map screen etc., app can request location manager to get current location of device in the same activity class.This approach is Not using continuous tracking saves battery used by app. and the Best suited when location is needed on a particular or few screens, but May give less accurate location

2. Timer/service based approach for continuous location tracking If app demands continuous location tracking in foreground as well as background, you can write your own service to track location on timely interval. In such a implementation, service starts listening to location updates for sometime interval and turns off all the updates for sometime.

Use of own service for location tracking gives ability to track location in background as well. Desired accuracy can be met if timer interval is decided accordingly. Geo fence based approach for continuous location tracking

3. Geo fence based approach for continuous location tracking Google Play Services has made it easy to monitor geo location area of certain radius which is called Geo fence. No need of writing own service for continuous location tracking. Better battery optimization as compared to timer/service based approach. This approach is not suitable when the app demands location tracking for minute location updates

for more information please visit http://mobisoftinfotech.com/3-ways-to-implement-efficient-location-tracking-in-android-applications/

like image 127
Jitesh Upadhyay Avatar answered Oct 26 '22 15:10

Jitesh Upadhyay


Does geofencing require you to continuously monitor the user's location ? - NO, it doesn't require you to monitor location.

Only requirements are

  1. Register your Geofence (one time action)
  2. Location Adapter should be on (System level setting, App can trigger dialog to turn on location adapter if disabled)
  3. Google Play services will automatically trigger actions and app will receive call back

Or will the LocationClient to which you add the Geofence automatically trigger when a transition has occurred ? - YES It will be automatically triggered. Make sure you set the right expiry timestamp and location adapter is on. App doesn't need to know the current location

[Optional]

Also, you can catch the right geofence errors to know, why didn't your geo-fence get triggered:

GEOFENCE_NOT_AVAILABLE Geofence service is not available now. Typically this is because the user turned off location access in settings > location access.

Constant Value: 1000

GEOFENCE_TOO_MANY_GEOFENCES Your app has registered more than 100 geofences. Remove unused ones before adding new geofences.

Constant Value: 1001

GEOFENCE_TOO_MANY_PENDING_INTENTS You have provided more than 5 different PendingIntents to the addGeofences(GoogleApiClient, GeofencingRequest, PendingIntent) call.

Constant Value: 1002

like image 3
Mayuri Khinvasara Avatar answered Oct 26 '22 15:10

Mayuri Khinvasara