简体   繁体   English

HMS 地理围栏不触发事件

[英]HMS Geofencing not triggering events

I'm having issues trying to use HMS Geofencing ( React Native ).我在尝试使用HMS Geofencing ( React Native ) 时遇到问题。 I'm setting up the service as shown below:我正在设置服务,如下所示:

  1. adding geofence to geofence list将地理围栏添加到地理围栏列表
const geofence = {
        latitude: latitude,
        longitude: longitude,
        radius: radius,
        uniqueId: identifier,
        conversions:
          HMSLocation.Geofence.Native.GeofenceConstants.ENTER_GEOFENCE_CONVERSION |
          HMSLocation.Geofence.Native.GeofenceConstants.EXIT_GEOFENCE_CONVERSION,
      }
geofenceList.push(geofence)
  1. starting geofence as explained in the documentation按照文档中的说明启动地理围栏
async startGeofencingTask(): Promise<void> {
    logger.info('Starting geofencing task')
    try {
      const regions = await this.loadGeofencedPositions()
      // getting geofenceList as shown before from an array of regions
      const geofenceList = this.convertToHMSGeofenceList(regions)
      const conversionType =
        HMSLocation.Geofence.Native.GeofenceRequestConstants.ENTER_INIT_CONVERSION |
        HMSLocation.Geofence.Native.GeofenceRequestConstants.EXIT_INIT_CONVERSION
      const coordinateType = HMSLocation.Geofence.Native.GeofenceRequestConstants.COORDINATE_TYPE_WGS_84

      HMSLocation.Geofence.Native.createGeofenceList(GEOFENCING_TASK_ID, geofenceList, conversionType, coordinateType)
      HMSLocation.Geofence.Events.registerGeofenceHeadlessTask(huaweiGeofencingTask)
      HMSLocation.Geofence.Events.addGeofenceEventListener(huaweiGeofencingTask)
    } catch (error) {
      logger.warn(`Unable to start geofencing task`, error)
    }
 }

With this setup I'm receiving only the first trigger, but since then I'm not getting any update neither while the app is in foreground nor in background.通过此设置,我只收到第一个触发器,但从那时起,无论应用程序处于前台还是后台,我都没有收到任何更新。 Any clue on why I'm getting just the initial update?关于为什么我只收到初始更新的任何线索?

EDIT: uses permissions are set as in the documentation:编辑:使用权限在文档中设置:

<uses-permission 
  android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission 
  android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission 
  android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

Make sure you the location permissions have been granted to the application and that you have registered a broadcast receiver in the Android Manifest.确保您已向应用程序授予位置权限,并且您已在 Android 清单中注册了广播接收器。

<receiver
    android:name=".geofence.GeoFenceBroadcastReceiver"
    android:exported="true">

    <intent-filter>
        <action android:name="com.huawei.hmssample.geofence.GeoFenceBroadcastReceiver.ACTION_PROCESS_LOCATION" />
    </intent-filter>

</receiver>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM