Setup the huawei location kit for getting device position overtime when apps in use, followed the setup from
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 });
};