Я пытаюсь использовать метод animateMarkerToCoordinate для маркера в React Native Maps.
В документации предлагается следующее:
componentWillReceiveProps(nextProps) {
const duration = 500
if (this.props.coordinate !== nextProps.coordinate) {
if (Platform.OS === 'android') {
if (this.marker) {
this.marker._component.animateMarkerToCoordinate(
nextProps.coordinate,
duration
);
}
} else {
this.state.coordinate.timing({
...nextProps.coordinate,
duration
}).start();
}
}
}
render() {
return (
<MapView initialRegion={...}>
<Marker.Animated
ref={marker => { this.marker = marker }}
coordinate={this.state.coordinate}
/>
</MapView>
);
}
Я пытался реализовать это в своем коде. Код в документации написан на древнем React (компонентWillReceiveProps устарел)
<MapView.Marker.Animated draggable
coordinate={this.state.playerMarkerPositionFuture}
title={"Player"}
description={"Player marker!"}
image={require('./assets/player_map_icon_small_transparent.png')}
onDragEnd={(event) => this.setState({ playerMarkerPositionFuture: event.nativeEvent.coordinate })}
onDragStart={this.movePlayerMarker()}
/>
...
movePlayerMarker = () => {
this.marker._component.animateMarkerToCoordinate(
nextProps.coordinate,
1000
);
}
Однако я получаю эту ошибку:
undefined is not an object (evaluating '_this.marker._component')
Нашел лучший пример здесь .