react-native - 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”
解决方案
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
}
);
推荐阅读
- azure - 如何在if语句中使用引用资源函数
- android - View.GONE vs View.INVISIBLE 从另一个线程更新 UI
- telegraf - Telegraf:指标中的字段和标签有什么区别?
- postgresql - 在 Postgres 中创建 JSONB 字段存在的部分索引会给我 PG::ProgramLimitExceeded。但为什么?
- uml - 在序列图中转到?
- shopware - 如何访问 Shopware 的 REST api
- c# - 在 C# 中从 UTF-8 转换
- python - 排序方法在 3.x python 中的工作方式与 2.x 不同
- excel - 如何计算两列中满足条件的行数?
- angular - 如何使用命令更改 CLI 或角度版本