我在我的 React-Native 应用程序中使用动态移动标记,为了使标记移动,我在一个间隔上进行了状态更新,用新的标记位置重新渲染屏幕。我也在尝试使用 react-native-maps-directions 它使用 google Routes API(需要花钱),我不能让路由 API 每秒被调用两次,因为这看起来很浪费(也因为我较差的)。
基本上,您是否知道一种方法可以继续重新渲染更新标记位置的部分而不重新渲染路线
这是我的渲染:
render() {
return (
<View>
<MapView
allOfMyProps={blahblahProps}
>
//This currently does and should re-render every time because I need them to move
{this.state.markers[1] !== null &&
this.state.markers.map((marker, index) => (
<MapView.Marker
key={index}
coordinate={{
latitude: marker.coordinate.latitude,
longitude: marker.coordinate.longitude,
}}
/>
))}
/// This is what renders the route, I want this to not re-render every time state changes
<MapViewDirections
origin={origin}
destination={destination}
apikey={GOOGLE_MAPS_API_KEY} //configure this right
strokeWidth={10}
strokeColor="green"
/>
</MapView>
</View>