【问题标题】:getTriggeringGeofences and getGeofenceTransition from LocationServices来自 LocationServices 的 getTriggeringGeofences 和 getGeofenceTransition
【发布时间】:2015-01-06 13:06:51
【问题描述】:

我注意到 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);
    }

【问题讨论】:

  • 绝对没有在不使用已弃用的 LocationClient 的情况下触发栅栏的示例:|我找到的最接近文档的是 github.com/jdellinger/… - 但它仍然使用 LocationClient 来获取栅栏触发器

标签: android location android-geofence location-client location-services


【解决方案1】:
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);  

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 2017-08-10
    • 2014-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    相关资源
    最近更新 更多