【发布时间】:2019-07-01 08:33:44
【问题描述】:
我目前正在为 Android 制作地理围栏应用,我关注了他们的 tutorial,但在使用模拟 GPS 定位应用时,我似乎无法正确触发 BroadcastReceiver。
我还启动了定位服务,它每 10000 毫秒间隔后从硬件获取位置。我完全遵循这个Github repository。
private void populateGeofenceList() {
for (Map.Entry<String, LatLng> entry : Constants.BAY_AREA_LANDMARKS.entrySet()) {
geofenceArrayList.add(new Geofence.Builder()
// Set the request ID of the geofence. This is a string to identify this
// geofence.
.setRequestId(entry.getKey())
// Set the circular region of this geofence.
.setCircularRegion(
entry.getValue().latitude,
entry.getValue().longitude,
Constants.GEOFENCE_RADIUS_IN_METERS
)
// Set the expiration duration of the geofence. This geofence gets automatically
// removed after this period of time.
.setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS)
// Set the transition types of interest. Alerts are only generated for these
// transition. We track entry and exit transitions in this sample.
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
Geofence.GEOFENCE_TRANSITION_EXIT)
.setLoiteringDelay(0)
// Create the geofence.
.build());
}
}
private GeofencingRequest getGeofencingRequest() {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
// The INITIAL_TRIGGER_ENTER flag indicates that geofencing service should trigger a
// GEOFENCE_TRANSITION_ENTER notification when the geofence is added and if the device
// is already inside that geofence.
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
// Add the geofences to be monitored by geofencing service.
builder.addGeofences(geofenceArrayList);
// Return a GeofencingRequest.
return builder.build();
}
【问题讨论】:
-
添加请求地理围栏触发信息的属性 setLoiteringDelay(10000)
标签: android gps geofencing android-geofence