我使用google-map-react渲染地图。在此,标记是可拖动的,它显示了在控制台中拖动的每个位置的纬度和长度。
我还有一个地理编码功能,它将lat和long转换为地址,我想将标记的坐标放到这个地理编码功能中,这样我就可以获得它的地址。 到目前为止,我已将lat和long坐标转换为数组: 继承我的代码:
lifecycle({
componentWillMount() {
const refs = {}
this.setState({
position: null,
onMarkerMounted: ref => {
refs.marker = ref;
},
onPositionChanged: () => {
const position = refs.marker.getPosition();
var res = position.toString();
var tes = res.split(","); /* want to pass tes to geocode */
console.log(tes);
}
})
},
}),
withScriptjs,
withGoogleMap
)((props) =>
<GoogleMap defaultZoom={8} defaultCenter={{ lat: 48.8583701, lng: 2.2922926 }}>
{props.isMarkerShown && <Marker position={{ lat: 48.8583701, lng: 2.2922926 }} draggable={true} ref={props.onMarkerMounted} onPositionChanged={props.onPositionChanged} />}
</GoogleMap>
)
Geocode.fromLatLng("48.8583701","2.2922926" /* Want to pass the value of tes here*/).then(
response => {
const address = response.results[0].formatted_address;
console.log(address);
},
error => {
console.error(error);
}
);
&#13;