作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我注意到 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);
}
最佳答案
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
然后您可以使用这些方法来检索转换和触发地理围栏:
int transition = geofencingEvent.getGeofenceTransition();
List<Geofence> geofenceList = geofencingEvent.getTriggeringGeofences();
关于android - 来自 LocationServices 的 getTriggeringGeofences 和 getGeofenceTransition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26840236/
我注意到 LocationClient 类目前已被弃用。我将它用于旅行应用程序。我更改了使用 LocationServices 而不是 LocationClient 的逻辑: https://deve
我是一名优秀的程序员,十分优秀!