反应本机地图可拖动标记 onDragEnd 位置?
React native maps draggable marker onDragEnd position?
我刚开始使用react native maps~0.22.1,我无法获取可拖动标记onDragend new position;
我遵循了文档,尽管它有点混乱,但结果是不确定的;
这是我的代码:
<Marker
ref={(ref) => { this.marker = ref; }}
draggable
onDragEnd={(t, map, coords) => this.setDestination(coords)}
coordinate={destination}
position={destination}
centerOffset={{ x: -18, y: -60 }}
anchor={{ x: 0.69, y: 1 }}
pinColor={COLOR.marker}
onDragStart={() => this.setMarkerPosition()}
/>
setDestination 函数:
setDestination(coords) {
const { destination } = this.props;
const lat = coords.lat();
const long = coords.lng();
console.log('seperate:', lat, long);
console.log('destina:', coords);
this.props
.dispatch($setDestination(coords.lat(), coords.lng()))
.catch((error) => this.props.dispatch(Activity.$toast('failure', error.message)));
this.setState((prevState) => ({
isVisible: !prevState.isVisible,
destination: destination[0].fullAddress,
}));
}
onDragEnd={(e) => {console.log('dragEnd', e.nativeEvent.coordinate)}}
我刚开始使用react native maps~0.22.1,我无法获取可拖动标记onDragend new position; 我遵循了文档,尽管它有点混乱,但结果是不确定的;
这是我的代码:
<Marker
ref={(ref) => { this.marker = ref; }}
draggable
onDragEnd={(t, map, coords) => this.setDestination(coords)}
coordinate={destination}
position={destination}
centerOffset={{ x: -18, y: -60 }}
anchor={{ x: 0.69, y: 1 }}
pinColor={COLOR.marker}
onDragStart={() => this.setMarkerPosition()}
/>
setDestination 函数:
setDestination(coords) {
const { destination } = this.props;
const lat = coords.lat();
const long = coords.lng();
console.log('seperate:', lat, long);
console.log('destina:', coords);
this.props
.dispatch($setDestination(coords.lat(), coords.lng()))
.catch((error) => this.props.dispatch(Activity.$toast('failure', error.message)));
this.setState((prevState) => ({
isVisible: !prevState.isVisible,
destination: destination[0].fullAddress,
}));
}
onDragEnd={(e) => {console.log('dragEnd', e.nativeEvent.coordinate)}}