问题描述
我正在尝试使用react-yandex-maps通过坐标获取地址。 我知道如何在功能组件中执行此操作。但是我确实需要使用类组件。 我需要获取ymap。但是不知道该怎么做。找不到解释清楚的文档。
这是我的代码:
import React,{ Component } from 'react'
import { YMaps,Map,ZoomControl,FullscreenControl,SearchControl,GeolocationControl,Placemark } from "react-yandex-maps";
export default class YMap extends Component {
constructor(props) {
super(props)
this.state = {
coords: [],mapState: {
center: [41.2825125,69.1392826],zoom: 9
},}
}
componentDidUpdate(prevProps,prevstate) {
if (prevProps.oldCoords !== this.props.oldCoords) {
this.setState({ coords: this.props.oldCoords })
}
}
onMapClick = (e) => {
const coords = e.get("coords");
this.setState({ coords: coords })
};
render() {
return (
<div>
<YMaps query={{ apikey: "" }}>
<Map
modules={["Placemark","geocode","geoObject.addon.balloon"]}
onClick={this.onMapClick}
state={this.state.mapState}
width='100%'
height='500px'
>
{this.state.coords ? <Placemark geometry={this.state.coords} /> : null}
<ZoomControl />
<FullscreenControl />
<SearchControl />
<GeolocationControl />
</Map>
</YMaps>
</div>
)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)