我对 Android Geofence Api 感到困惑。所以方法说.setTransitionTypes(int)。但是,当我尝试将我的地理围栏设置为同时监视特定地理围栏的进入和退出时,它只会监视我将其设置为要监视的转换的转换类型。
这是我的代码示例
public Geofence toGeofence() {
// Build a new Geofence object
return new Geofence.Builder()
.setRequestId(getId())
.setTransitionTypes(getTransitionType()) //Geofence.GEOFENCE_TRANSITION_ENTER
.setTransitionTypes(getTransitionType2())// Geofence.GEOFENCE_TRANSITION_EXIT
.setCircularRegion(
getLatitude(), getLongitude(), getRadius())
.setExpirationDuration(mExpirationDuration)
.build();}
这只监视最后一个转换类型集,即退出转换,我已经为同一区域创建了 2 个地理围栏,一个用于监视每个转换,但我觉得这不是可行的方法。有帮助吗?
最佳答案
对于那些可能遇到这个问题的人来说,设置多个过渡类型的方法是添加一个 |在每个转换类型之间。
geofence.setTransitionType(getTransitionType() | getTransitionType2());
关于android - 具有多个转换类型集的地理围栏 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24313162/