我正在注册这样的Geofences:
public void addGeofencing(final MyObject myObject){
Geofence geofence = (new Geofence.Builder()
.setRequestId(myObject.getId())
.setCircularRegion(
myObject.getLat(),
myObject.getLon(),
RADIUS_IN_METERS
)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
Geofence.GEOFENCE_TRANSITION_EXIT)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build());
client.addGeofences(getGeofencingRequest(geofence),getGeofencePendingIntent(myObject.getExtraString))
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
System.out.println("GEOFENCE WORKED");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
System.out.println("GEOFENCE FAILED");
}
});
}
private GeofencingRequest getGeofencingRequest(Geofence geofence) {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofence(geofence);
return builder.build();
}
private PendingIntent getGeofencePendingIntent(String extraString) {
Intent intent = new Intent(context, GeofenceTransitionsIntentService.class);
intent.putExtra("extra",extraString);
return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT);
}
但在这样做的同时,我注意到仅针对我添加的最新地理围栏触发了进入和退出事件。为什么这样,我该如何解决?我为每个地理围栏设置了唯一的请求ID,以便防止出现这种问题?