GetTriggeringGeofences and getGeofenceTransition from LocationServices

I noticed that the LocationClient class is currently deprecated. I used it for a travel app. and I changed the logic of using LocationServices instead of LocationClient: https://developer.android.com/reference/com/google/android/gms/location/LocationServices.html

Now the problem is that I cannot get getTriggeringGeofences and getGeofenceTransition from LocationServices.Geofence or GoogleApiClient. How to do it?

This is the code of my old BroadcastReceiver:

int transitionType = LocationClient.getGeofenceTransition(intent); if(transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) { List<Geofence> triggerList = LocationClient.getTriggeringGeofences(intent); for (Geofence geofence : triggerList) { Log.i("", "geof: " + transitionType + " GPS zone " + geofence.getRequestId()); if(geofence.getRequestId().contentEquals("1")) { Utils.appendLog("GEOFENCE: exited current position GPS Zone"); MyApp.getInstance().disableGeofence(); addLoc(); } } }else if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER){ List<Geofence> triggerList = LocationClient.getTriggeringGeofences(intent); for (Geofence geofence : triggerList) { Log.i("", "geof: " + transitionType + " GPS zone " + geofence.getRequestId()); if(geofence.getRequestId().contentEquals("2")) { Utils.appendLog("GEOFENCE: entered destination position GPS Zone"); MyApp.getInstance().disableGeofence(); } } }else{ Log.e("", "Geofence transition error: " + transitionType); } 
+5
source share
1 answer
 GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); 

And then you can use these methods to extract the transition and triggering geofences:

 int transition = geofencingEvent.getGeofenceTransition(); List<Geofence> geofenceList = geofencingEvent.getTriggeringGeofences(); 
+6
source

Source: https://habr.com/ru/post/1206549/


All Articles