4

在我构建地理围栏的方法中,我收到一个错误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();
}
4

2 回答 2

7

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

于 2014-07-05T11:13:01.867 回答
-2

是的,所以我忘了声明常量。呸!这是我使用的声明:

long NEVER_EXPIRE = -1;
int GEOFENCE_TRANSITION_ENTER = 1;

更多关于这里的问题:https ://developer.android.com/reference/com/google/android/gms/location/Geofence.html

于 2014-03-15T05:39:23.413 回答