【问题标题】:Geofence with mock GPS provider带有模拟 GPS 提供商的地理围栏
【发布时间】: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


【解决方案1】:

一些建议:

  1. 检查您的定位适配器是否已打开。
  2. 检查您是否已授予位置permissions

  3. 检查纬度、经度的值是否正确。谷歌地图是否显示正确的位置,您期望触发的位置。

  4. 如果需要,设置停留时间 (setLoiteringDelay(10000))。
  5. 您是否设置了 BroadcastReceiver 以接收 documentation 中提到的回调。

【讨论】:

    猜你喜欢
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多