在react-leaflet中点击地图时如何获取地址(街道、房屋等)?

问题描述 投票:0回答:1

当您点击地图时,有必要显示地址(街道、房屋等)。现在当你点击时,我就有了纬度和经度。

如何实施?发送带有纬度和经度的请求?

javascript reactjs leaflet react-leaflet
1个回答
0
投票

您可以使用来自 https://nominatim.org/release-docs/develop/api/Reverse/https://developers.google.com/maps/documentation/javascript/examples/geocoding- 的反向地理编码反转.

使用 openstreetmap api 的示例:

const reverseGeocoding = await axios.get(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2`,);

const { city, postcode, road, suburb, town } = reverseGeocoding.data.address;

const displayLocation = `${road}, ${suburb ? `${suburb},` : ''}${postcode}, ${city || town}`,
© www.soinside.com 2019 - 2024. All rights reserved.