Home > Back-end >  Huawei Location Kit for React Native, addFusedLocationEventListener method doesn't trigger call
Huawei Location Kit for React Native, addFusedLocationEventListener method doesn't trigger call

Time:11-25

Setup the huawei location kit for getting device position overtime when apps in use, followed the setup from enter image description here enter image description here

CodePudding user response:

I think it might be a usage issue. The function of addingFusedLocationEventListener is to add FusedLocationEvent Listener. This function is triggered only when FusedLocationEvent happen.

In your description, delete removeFusedLocationEventListener after addFusedLocationEventListener, the added listener is also deleted.

In addition, you are advised to use independent functions instead of directly defining them in input parameters.

handleLocationUpdate = (locationResult) => { console.log(locationResult); this.setState({ locationCallbackResult: locationResult }); }

requestLocationCallbackWithListener = () => {
  HMSLocation.FusedLocation.Native.requestLocationUpdatesWithCallbackEx(locationRequest)
    .then((res) => this.setState({ reqCode: res.requestCode }))
    .catch((err) => alert(err.message));
  HMSLocation.FusedLocation.Events.addFusedLocationEventListener(this.handleLocationUpdate);
  this.setState({ autoUpdateEnabled: true });
};

enter image description here

  • Related