首页 > 解决方案 > React Native中,使用expo-location,iOS中gps位置刷新率太低

问题描述

我使用 expo-cli 做了一个应用程序,但我在 ios 和 android 上得到了不一致的结果,特别是在这部分代码中,每次我从手机获取 GPS 位置时,我都会执行一个循环代码,特别是速度.

import * as Location from 'expo-location';
import React from 'react';

class HomeScreen extends React.Component {

  componentDidMount(){
    let watchID = Location.watchPositionAsync(
      {accuracy: 6, timeInterval: 500},
      (position) => {
        // my recurrent code
      }
    );
  }

}

即使我将它设置为每 0.5 秒恢复一次速度,Android 手机也相当合理,每两秒一次,但 iOS 设备玩得不是很好,有时要等待长达 30 秒才能更新,例如速度从一个测量值跳到下一个测量值 + 30 mph。

有什么办法可以提高 iOS 中的 GPS 刷新率?也许是我还没有弄清楚的记录问题?

“博览会”:“36.0.0”“博览会位置”:“〜8.0.0”“反应”:“16.13.1”

标签: react-nativeexporeact-native-ios

解决方案


Self-answer: In the end it was a bug that still persists in some form inside expo-location: It's required to set the distanceInterval option in the options array of the Location.watchPositionAsync() function:

let watchID = Location.watchPositionAsync(
      { accuracy: 6, timeInterval: 500, distanceInterval: 0 },
      (position) => {
        // my recurrent code
      }
    );

推荐阅读