Sam
Sam

Reputation: 45

Android Geofencing: Trigger only while outside geofence

I am making a geofencing application, which must trigger notification constantly while the device is outside the geofence, not only on exit.

I have tried using Geofencing API through the training example given in Google android developer training page. But, I got notification only when the device enters, dwell or exit.

According to what I have researched till now in both SO and google, there are only three types of transitions handled in Geofencing API: Enter, Dwell and Exit. And the notification starts only when device enters the geofence, till it exits.

Can anyone help me out how to make it work?

Upvotes: 3

Views: 940

Answers (2)

Mayuri Khinvasara
Mayuri Khinvasara

Reputation: 1517

Incase you want your own custom exit trigger, when you are outside the fence. You can write your custom action by measuring distance(lat,long) between your current location(FusedLocationProvider) and the fence location (lat, long).

You can use below methods available in Android Location API to measure the difference and generate a custom trigger to indicate that you are outside the fence.

Typically this is what you need to do

if[ (difference in location) > (Radius of your geo fence) ] -> Custom Exit of Fence Action

  1. distanceTo
  2. distanceBetween (Provide both your current lat,long and your fence lat,long here)

Upvotes: 2

Thomas R.
Thomas R.

Reputation: 8073

That is not possible that way. It does not make any sense outside the geofence area. That is not an usecase of geofence.

You can try to specify broader range of the area and then check the geocoordinates if this is outside of your area you want to have.

Upvotes: 1

Related Questions