小编Ruk*_*dhi的帖子

当我使用地理围栏时,进入或退出触发器不会被触发

我正在我的 Android 应用程序中使用地理围栏,点击此链接

我正在默认可见活动中创建和添加地理围栏对象,并使用上面链接中所述的帮助 IntentService 监听其事件。

地理围栏对象已成功添加,但当我使用真实设备对其进行测试并移入/移出定义的地理围栏区域时,其 ENTER/EXIT 事件不会被触发。

我已经用 100m、50m、500m、1500m 和 2000m 的半径对其进行了测试,但在任何情况下它都不起作用。

这就是我创建和添加地理围栏的方式:

 mGeofencingClient = LocationServices.getGeofencingClient(DashboardActivity.this);

Geofence geofence = new Geofence.Builder()
                // Set the request ID of the geofence. This is a string to identify this
                // geofence.
                .setRequestId(REQUEST_ID)

                .setCircularRegion(
                        22.703617,
                        75.873409,
                        Constants.GEOFENCE_RADIUS_IN_METERS
                )
                .setExpirationDuration(Geofence.NEVER_EXPIRE)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                        Geofence.GEOFENCE_TRANSITION_EXIT )

                .build();
        mGeofenceList.add(geofence);

        GeofencingRequest geofencingRequest = new GeofencingRequest.Builder()
                .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER|GeofencingRequest.INITIAL_TRIGGER_EXIT)
                .addGeofences(mGeofenceList).build();

        Intent intents = new Intent(this, GeofenceTransitionsIntentService.class);
        mGeofencePendingIntent = PendingIntent.getService(DashboardActivity.this, 0, intents, PendingIntent.
                FLAG_UPDATE_CURRENT);


        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) …
Run Code Online (Sandbox Code Playgroud)

android google-maps-api-3 geofencing android-geofence

5
推荐指数
0
解决办法
1324
查看次数