我想在视频开始记录后立即开始记录位置,并以此来确定应用程序开始记录后我移动的速度。我将功能记录与按钮连接在一起,并且同时使用了具有地理位置的React Native方法和Expo方法。即使正确测量了纬度和经度,也无法从GPS读取速度。
我已经使用了Expo和React Native Geolocation API,但是它们都无法正常工作。我在代码下方附加了内容。
record = async () => {
this.speedCounter();
...
}
speedCounter = async () => {
navigator.geolocation.watchPosition(
this.onPositionChange,
(error) => { console.log(error); },
{ enableHighAccuracy: true, timeout: 500,maximumAge:0 }
)
}
onPositionChange = location => {
//console.log(location);
console.log(location.coords.speed);
this.setState({speed:location.coords.speed});
};
async componentDidMount() {
this._getLocationAsync();
}
_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessageSpeed: 'Permission to access location was denied',
});
}
};