来自LocationServices的getTriggeringGeofences和getGeofenceTransition

ros*_*lin 5 android location android-geofence location-client location-services

我注意到目前已弃用了LocationClient类.我正在使用它作为旅行应用程序.我改变逻辑使用LocationServices而不是LocationClient:https: //developer.android.com/reference/com/google/android/gms/location/LocationServices.html

现在问题是我无法从LocationServices.Geofence或GoogleApiClient获取getTriggeringGeofences和getGeofenceTransition.我怎么做?

这是我的旧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);
    }
Run Code Online (Sandbox Code Playgroud)

Ant*_*ine 6

GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);  
Run Code Online (Sandbox Code Playgroud)

然后您可以使用这些方法来检索转换和触发地理围栏:

int transition = geofencingEvent.getGeofenceTransition();
List<Geofence> geofenceList = geofencingEvent.getTriggeringGeofences();
Run Code Online (Sandbox Code Playgroud)