-1

I have integrated Geofences in my application. I have set radius as 100m in India added entry and exit transition types. I used fake location app to set my location in USA to begin with and never even entered my geofence in India, however I am getting an exit.

I thought exit transition is only triggered when you entered first and then exited the Geofence. I couldn't find any proper definition for Geofence Exit.

Please help, thanks in advance

MrUpsidown
  • 19,965
  • 12
  • 63
  • 114

1 Answers1

1

When you are building GeofencingRequest object, you have to give initial trigger which you want to catch. See the sample code below.

private fun getGeofencingRequest(): GeofencingRequest {
    return GeofencingRequest.Builder().apply {
        setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER) //This is initial action which you want to catch first
        addGeofences(geofenceList)
    }.build()
}

May be, in setInitialTrigger() method you have entered GeofencingRequest.INITIAL_TRIGGER_EXIT. So, that you are getting exit trigger at start.

Note:- Above sample code will trigger enter event if you are already inside your geofence. If you don't want to get any initial trigger, you should use NO_INITIAL_TRIGGER.

Jaydip Kalkani
  • 1,881
  • 6
  • 17
  • 49
  • Thank you so much !! Now i understand why, I can also do ```.setTransitionTypes( com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER | com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT ``` to catch entering and exit after initial trigger – Mysterious_android Sep 18 '18 at 05:39
  • @Mysterious_android yes, absolutely. Keep it up. – Jaydip Kalkani Sep 18 '18 at 05:47