I'm trying to get address by coordinates using react-yandex-maps. I know how to do it in functional component. But I really need to use class component instead. I need to get ymaps. But have no idea how to do that. Couldn't find well-explained documentation for it.
Here is my code:
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>
)
}
}