Setup the huawei location kit for getting device position overtime when apps in use, followed the setup from https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/config-agc-0000001050197382-V1
we don't have real huawei device, we're using cloud debugging
Try implement to watch the gps location overtime with all these syntax
// ------ Parent ------
// this put on the parent useEffect
HMSLocation.LocationKit.Native.init()
.then(() => console.log('----------Success Initialize----------'))
.catch((err) => alert(err.message))
// ------ Child ------
const stopWatchingLocation = () => {
if (hasHms) {
HMSLocation.FusedLocation.Events.removeFusedLocationEventListener(
(res: LocationResult) => console.log('remove add listener', res),
)
}
}
const startWatchingLocation = async () => {
if (hasHms) {
HMSLocation.FusedLocation.Native.requestLocationUpdatesWithCallbackEx(
hwGeolocationOptions,
)
.then((res) => console.log('success request', res))
.catch((error) => console.log('failed request', error))
HMSLocation.FusedLocation.Events.addFusedLocationEventListener(
(res: LocationResult) => console.log('result', res.lastHWLocation)
)
}
}
// implementation of add & remove event listener
useEffect(() => {
startWatchingLocation() // inside here invoke addFusedLocationEventListener
return stopWatchingLocation // inside here invoke, cleanup function removeFusedLocationEventListener
}, [])
The code successfully invoke the init, requestLocationUpdatesWithCallbackEx, but console log from addFusedLocationEventListener never invoke
Already turn on hms core app permission for location, hasPermission also returned true
Tried the locationRequest options from problem with react native @hmscore/react-native-hms-location comments, still not working
How we can fix these??
I think it might be a usage issue. The function of
addingFusedLocationEventListeneris to addFusedLocationEventListener. This function is triggered only when FusedLocationEvent happen.In your description, delete
removeFusedLocationEventListenerafteraddFusedLocationEventListener, the added listener is also deleted.In addition, you are advised to use independent functions instead of directly defining them in input parameters.