设置华为定位包,用于在应用程序使用时超时获取设备位置,按照https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/config-agc-0000001050197382-V1中的设置
我们没有真正的华为设备,我们正在使用云调试
尝试使用所有这些语法来观察 gps 位置超时
// ------ 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
}, [])
代码成功调用init
, requestLocationUpdatesWithCallbackEx
, 但控制台日志addFusedLocationEventListener
从未调用
已经开启hms core app的位置权限,hasPermission
也返回true
尝试了react native @hmscore/react-native-hms-locationlocationRequest
评论的问题选项,仍然无法正常工作
我们如何解决这些问题?