setExpirationDuration(NEVER_EXPIRE) and setTransitionTypes(GEOFENCE_TRANSITION_ENTER) giving error

StackOverflow https://stackoverflow.com/questions/22420004

  •  15-06-2023
  •  | 
  •  

Question

In my method for building a geofence, I am getting an error on ExpirationDuration(NEVER_EXPIRE) and setTransitionTypes(GEOFENCE_TRANSITION_ENTER) stating that they can't be resolved to a variable. Why is this happening?

My method:

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();
}
Was it helpful?

Solution 2

Yeah, so I forgot to declare the constants. Duh! Here's the declarations I used:

long NEVER_EXPIRE = -1;
int GEOFENCE_TRANSITION_ENTER = 1;

More on the matter here: https://developer.android.com/reference/com/google/android/gms/location/Geofence.html

OTHER TIPS

Those constants are already declared in the Geofence Class you reference, so jut use them as geofence.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top