【发布时间】:2021-06-06 06:00:12
【问题描述】:
我每 5 秒从我的数据库中获取坐标,我的标记是动态的,这是我的渲染方法
console.log('render'+this.state.driverLocation.latitude +' '+this.state.driverLocation.longitude);
let marker = null;
marker = <MapView.Marker title='This is you' coordinate={this.state.driverLocation } />;
return (
<View style={styles.container}>
<MapView
initialRegion={this.state.focusedLocation}
region={!this.state.locationChosen ? this.state.focusedLocation : null}
style={styles.map}
onPress={this.pickLocationHandler}
ref={ref => this.map = ref}
>
{marker}
</MapView>
render 中的日志语句显示 driverLocation 每 5 秒更改一次,但标记保持在初始位置(定义状态时给出的坐标)。
我的代码有问题吗?我需要添加一些东西吗?任何帮助将不胜感激。
【问题讨论】:
-
嘿!我已经找到了解决方案,但感谢您的回复。
标签: react-native react-native-maps