На все три вопроса ответ положительный.
Первый, вы можете определить точность, которую вы хотите получить в Builder of Geofence, как это
new Geofence.Builder()
.setRequestId(key)
.setCircularRegion(lat, lang, 150)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.setLoiteringDelay(1000)
.build();
Я установил точность на 150 м (есть одна вещь, которую вы должны знать, это то, что чем больше точность вы устанавливаете, тем большую мощность вы используете)
Для второго и третьего вы можете установить для TransitionTypes значение Geofence.GEOFENCE_TRANSITION_DWELL, чтобы узнать, находится ли пользователь какое-то время в одном месте. В то же время вы можете использовать PendingIntent для отправки широковещательной рассылки, когда это условие соответствует. Полный код приведен ниже
Geofence geofence = getGeofence(lat, lng, key);
geofencingClient.addGeofences(
getGeofencingRequest(geofence),
getGeofencePendingIntent(title, location, id))
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
}else{
}
});
код getGeofencingRequest
private GeofencingRequest getGeofencingRequest(Geofence geofence) {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofence(geofence);
return builder.build();
}
Код getGeofencePendingIntent
private PendingIntent getGeofencePendingIntent(String title, String location, long id) {
Intent i = new Intent("add your unique ID for the broadcast");
Bundle bundle = new Bundle();
bundle.putLong(Reminder.ID, id);
bundle.putString(Reminder.LOCATION_NAME, location);
bundle.putString(Reminder.TITLE, title);
i.putExtras(bundle);
return PendingIntent.getBroadcast(
getContext(),
(int) id,
i,
0
);
}