5

Ich habe festgestellt, dass die LocationClient-Klasse derzeit veraltet ist. Ich benutzte es für eine Reise-App. und ich änderte die Logik LocationServices zu verwenden, anstatt LocationClient: https://developer.android.com/reference/com/google/android/gms/location/LocationServices.htmlgetTriggeringGeofences und getGeofenceTransition von LocationServices

Nun das Problem ist, kann ich nicht bekommen getTriggeringGeofences und getGeofenceTransition von LocationServices.Geofence oder der GoogleApiClient. Wie mache ich das?

Dies ist der Code von meinem alten 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); 
    } 
+1

Es gibt absolut kein Beispiel für Auslösen von Zäunen ohne Verwendung des veralteten LocationClients: | Der Dokumentation, die ich gefunden habe, ist dies am nächsten: https://github.com/jdellinger/AnDevConNov2014-LocationServicesDemoProject/tree/newapi - aber es verwendet immer noch den LocationClient, um Fence-Trigger aufzunehmen – InquisitorJax

Antwort

6
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); 

Und dann können Sie diese Methoden verwenden, um den Übergang und die auslösenden geofences abzurufen:

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