ios - 使用 React Native 中的 Uber 或 Ola 等动画在谷歌地图上旋转标记
问题描述
我正在做一个类似于 UBER 或 OLA 的项目。我为此使用了react-native-maps库。我使用 React Native 地理位置来获取当前位置。我还参考了这个react-native-maps 示例。但标记的旋转不起作用。谁能帮忙?我哪里错了?
这段代码在 Android 上运行良好,但在 iOS 上不行
提前致谢。
下面我分享我的代码
render(){
return(
<MapView
ref={component => (this.map = component)}
provider={PROVIDER_GOOGLE}
style={styles.mapStyle}
>
<Marker. Animated
coordinate={{
latitude: this.state.currentLocation.latitude,
longitude: this.state.currentLocation.longitude
}}
ref={marker => {
this.marker = marker;
}}
flat
style={{
transform: [
{
rotate:
this.state.currentLocation.heading ===
undefined
? "0deg"
: `${this.state.currentLocation.heading}deg`
}
]
}}
image={"rickshaw"}
/>
)}
我已经更新了componentDidUpdate中的标记位置
componentDidUpdate(prevProps, prevState) {
if (prevState.currentLocation !== this.state.currentLocation) {
let newCoordinate = this.state.currentLocation;
let previousLocation = prevState.currentLocation;
if (utility.getOS() === "android") {
console.log("update marker");
if (this.marker) {
this.marker._component.animateMarkerToCoordinate(
this.state.currentLocation,
1000
);
}
} else {
if (newCoordinate !== null && previousLocation !== null) {
const oldCoordinate = new AnimatedRegion({
latitude: previousLocation.latitude,
longitude: previousLocation.longitude
});
oldCoordinate.timing(newCoordinate).start();
}
}
}
}
解决方案
推荐阅读
- sql - TSQL 查询的问题仅根据需要返回具有值而不是 0 的月份
- python - Pygame 砖块在碰撞时会消失,但会在几秒钟内重新出现
- c - 我需要使用哪些标头变量来提取 tar 文件
- javascript - 如何使用 Heroku 上的库部署 monorepo
- python - Discord.py 将角色添加到成员
- python - 在不改变颜色的情况下将 CMYK 转换为 RGB
- c# - 如何使韵律持续时间适用于所有语音性别?
- python - 下载错误:错误:警告:无法在 heroku 中使用 ffprobe 获取文件音频编解码器
- python - pvlib 未校正 calcparams_desoto 中的串联电阻和校正分流电阻,与参考不一致
- c++ - 重载运算符“<<”c ++的意外行为