React native 在iPhone 7上,React本地地理位置标题始终为-1

React native 在iPhone 7上,React本地地理位置标题始终为-1,react-native,geolocation,react-native-ios,React Native,Geolocation,React Native Ios,我面临着一个问题,一周内我无法解决 任务:我注意观察设备的位置和方向 解决方案:我使用文档中描述的方法 this.watcher = navigator.geolocation.watchPosition((position) => { const latitude = position.coords.latitude; const longitude = position.coords.longitude; const heading = position.coo

我面临着一个问题,一周内我无法解决

任务:我注意观察设备的位置和方向

解决方案:我使用文档中描述的方法

this.watcher = navigator.geolocation.watchPosition((position) => {
    const latitude = position.coords.latitude;
    const longitude = position.coords.longitude;
    const heading = position.coords.heading;

    this.setState({
      latitude: latitude,
      longitude: longitude,
      heading: heading
    });
  },
  (error) => {
     console.log(`error: ${error}`);
  }, 
  {
    enableHighAccuracy: true,
    timeout: 10000,
    maximumAge: 0
  });
Eeverything在模拟器上运行良好。但在真正的iOS设备上,标题总是-1。 我的项目使用RN 0.54。然而,我刚刚通过
react native init
用RN 0.56创建了一个新项目,其行为是相同的

问题是,在react native maps包中,用户方向以完美的方式呈现,因此我假设react native可能存在一些问题


有什么帮助吗?

使用
Location.getHeadingAsync()
我可以将航向设置为非-1

查看此链接了解我正在使用的expo方法:

由于React Native geolocation是web geolocation()的扩展, 它将方向(航向)作为最后两个位置之间的差值。在低速或用户停留时不工作(返回-1)

这很奇怪,因为我希望RN能从内置的“指南针”中获取设备的航向

弹出应用的解决方案:使用第三方库,即使在用户停留的时候,也能让设备停止运行


世博会解决方案:应该不会有这样的问题,因为世博会使用内置指南针而不是web地理定位。

我不使用世博会,我开发的是弹出式rn应用程序