【发布时间】:2021-09-17 09:37:26
【问题描述】:
是否可以获得Geofence gps 位置详细信息 - 即越过围栏的点?
- 我在位置 x,y, 半径处设置了地理围栏
- 我穿过栅栏,我的位置是 x2, y2
如何在不再次调用 GPS 请求的情况下轻松获取 x2、y2?
class GeofenceLocationReceiver: BroadcastReceiver() {
[...]
override fun onReceive(context: Context?, intent: Intent?) {
val geofencingEvent = GeofencingEvent.fromIntent(intent)
if (geofencingEvent.hasError()) {
val errorMessage = GeofenceStatusCodes.getStatusCodeString(geofencingEvent.errorCode)
Log.e(Category.LOCATION, "GEOFENCE result has errors: $errorMessage")
return
}
if (geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
geofencingEvent.triggeringGeofences.firstOrNull()?.let {
val geofenceId = it.requestId
// HERE - HOW TO GET X2, Y2 - GPS coordinates?
}
} else {
Log.e(Category.LOCATION, "INVALID TYPE")
}
}
}
【问题讨论】:
标签: geofencing android-gps android-geofence