【发布时间】:2018-08-14 14:18:55
【问题描述】:
我正在使用 react-native-maps 在我的 React Native 应用程序中显示地图视图。我按照example 为标记坐标设置动画,但每当我调用 animateMarkerToCoordinate() 方法时,我都会收到未定义的错误。在做一些检查后,我尝试在我的 componentWillReceiveProps 中调用上述方法。
这是我的组件WillReceiveProps:
componentWillReceiveProps(nextProps) {
if(nextProps.user && JSON.stringify(nextProps.user.profile.location) != JSON.stringify(this.props.user.profile.location)) {
const userCoordinate = this.state.userCoordinate
const newUserCoordinate = {
latitude: nextProps.user.profile.location.latitude,
longitude: nextProps.user.profile.location.longitude,
}
if (Platform.OS === 'android') {
console.log('platform = android')
if (this.userMarker) {
// none of this options work, both return undefined
this.userMarker._component.animateMarkerToCoordinate(newUserCoordinate, 500)
this.userMarker.animateMarkerToCoordinate(newUserCoordinate, 500)
}
} else {
userCoordinate.timing(newUserCoordinate).start();
}
}
}
这是我的渲染方法的 MapView 部分:
<MapView
style={styles.map}
initialRegion={this.regionFrom(this.props.user.profile.location)}
mapType='standard' >
<Marker.Animated
ref={marker => { this.userMarker = marker; }}
coordinate={this.state.userCoordinate}
onPress={() => this.handleOnPress()} >
<UserMarker loaded={this.props.loaded} />
</Marker.Animated>
</MapView>
如果有帮助,我的状态:
constructor(props) {
super(props);
this.state = {
region: this.regionFrom(this.props.user.profile.location),
profileSelected: null,
userPreviewVisible: false,
userCoordinate: new AnimatedRegion({
latitude: props.user.profile.location.latitude,
longitude: props.user.profile.location.longitude,
}),
}
}
这是日志错误(每当我使用 marker._component 或只是标记时都会出现相同的错误,我尝试在代码中更改它以查看是否是问题所在):
我必须将它添加为图片,因为当我将堆栈跟踪作为文本发布时,堆栈溢出的编辑器会出错。
请注意,我只在 android 上进行测试,而且我真的被困在了这个中。如果有人可以提供帮助,我将不胜感激。谢谢。
【问题讨论】:
标签: javascript android google-maps react-native react-native-maps