2

我正在关注 @hmscore/react-native-hms-location 文档和 react native,我正在尝试使用 requestLocationUpdatesWithCallback() 和 addFusedLocationEventListener() 函数持续获取位置信息我可以从 requestLocationUpdatesWithCallback() 获取请求代码但是addFusedLocationEventListener() 什么都不返回,就像它没有触发一样

 HMSLocation.FusedLocation.Native.requestLocationUpdatesWithCallbackEx(locationRequest)
  .then((res) => console.log(res))
  .catch((err) => alert(err.message))
  

////////////////////////

HMSLocation.FusedLocation.Events.addFusedLocationEventListener(handleLocationUpdate)


 /////////////////////


const handleLocationUpdate = (locationResult) => console.log(locationResult)

任何解决方案

4

2 回答 2

0

从表面上看,这应该可行。但是,您可能缺少某些权限。请使用 requestPermission() 和 hasPermission() 函数来请求并检查您是否确实具有实际接收任何位置信息的必要权限。

您可能还想使用 setMockMode 和 setMockLocation 创建一个模拟位置,以确保您的程序按预期工作。

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References-V1/fusedlocation-0000001050043303-V1#EN-US_TOPIC_0000001050140366__section1060819319425

于 2021-05-13T18:15:55.597 回答
0

位置持续时间取决于locationRequest配置。

Demo中提供的参数设置不支持连续获取位置信息。建议配置如下参数:

    const locationRequest = {
      priority: HMSLocation.FusedLocation.Native.PriorityConstants.PRIORITY_HIGH_ACCURACY,
      interval: 60000,    
      numUpdates: 2147483647, 
      fastestInterval: 30000.0,  
      expirationTimeDuration: 2147483647, 
      smallestDisplacement: 0.0,
      language: 'en',
      countryCode: 'en',
    };

有关参数的详细信息,请参阅文档

于 2021-05-12T02:55:26.390 回答