setExpirationDuration(NEVER_EXPIRE)和setTransitionTypes(GEOFENCE_TRANSITION_ENTER)给出错误

时间:2014-03-15 05:32:59

标签: android android-geofence

在我构建地理围栏的方法中,我在ExpirationDuration(NEVER_EXPIRE)setTransitionTypes(GEOFENCE_TRANSITION_ENTER)上收到错误,指出无法将其解析为变量。为什么会这样?

我的方法:

private void buildGeofence(){
    LatLng geofencePoint = marker.getPosition();
    int radius = 1610;
    Geofence.Builder geofence = new Geofence.Builder();
    geofence.setCircularRegion(geofencePoint.latitude,geofencePoint.longitude, radius);
    geofence.setExpirationDuration(NEVER_EXPIRE);
    geofence.setTransitionTypes(GEOFENCE_TRANSITION_ENTER);
    geofence.setNotificationResponsiveness(0);
    geofence.build();
}

2 个答案:

答案 0 :(得分:5)

这些常量已在您引用的Geofence类中声明,因此请将它们用作geofence.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER);

答案 1 :(得分:-2)

是的,所以我忘了宣布常数。咄!这是我使用的声明:

long NEVER_EXPIRE = -1;
int GEOFENCE_TRANSITION_ENTER = 1;

有关此事的更多信息:https://developer.android.com/reference/com/google/android/gms/location/Geofence.html