gpt4 book ai didi

javascript - 如何在 React Native map 上显示连续移动的汽车图标?

转载 作者:数据小太阳 更新时间:2023-10-29 04:48:57 25 4
gpt4 key购买 nike

我正在使用 airbnb 的 react-native-maps 库来开发我的 android react native 应用程序。此应用在主页上显示 map 和汽车图标。

它工作正常但是当汽车移动并且汽车坐标不断变化时, map 渲染不流畅。带有汽车图标的 MapView 标记沿着路径从一个点跳到另一个点。我的期望是在 map 上显示一个连续移动的对象,就像它在谷歌地图上显示的那样。

这是我的代码:

this.state = {
latitude: 22.55231,
longitude: 88.56772,
angle: 0
}

componentDidMount(){
navigator.geolocation.getCurrentPosition(
position => {
let latitude = position.coords.latitude;
let longitude = position.coords.longitude;
let angle = position.coords.heading;
this.setState({latitude, longitude, angle});
},
error => console.log(error),
{
// enableHighAccuracy: true
}
);

navigator.geolocation.watchPosition(
position => {
let latitude = position.coords.latitude;
let longitude = position.coords.longitude;
let angle = position.coords.heading;
this.setState({latitude, longitude, angle});
},
error => console.log(error),
{
// enableHighAccuracy: true
}
);
}

getMapRegion(){
return {
latitude: this.state.latitude,
longitude: this.state.longitude,
latitudeDelta: 0.9271,
longitudeDelta: ASPECT_RATIO * 0.9271
}
}

render(){
let angle = this.state.angle || 0;
return(
<MapView style={styles.map}
showUserLocation={true}
followUserLocation={true}
region={this.getMapRegion()}>
<MapView.Marker
title={'Hi'}
style={{
transform: { rotate: `${angle}deg` },
width: 20,
height: 20
}}
image={require('../../../images/car-marker-2.png')}
coordinate={{ latitude: this.state.latitude, longitude: this.state.longitude }}/>
</MapView>
);
}

非常感谢对此的任何帮助。

最佳答案

我认为汽车正在“跳跃”,因为这是 GPS 计算新坐标所花费的时间,而您只是发送新坐标,但并未缓和过渡。请记住,GPS 不会立即工作。

您可能想要为标记设置动画。请参阅此处的“动画标记位置”:https://github.com/airbnb/react-native-maps

关于javascript - 如何在 React Native map 上显示连续移动的汽车图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46878226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com