当您点击地图时,有必要显示地址(街道、房屋等)。现在当你点击时,我就有了纬度和经度。
如何实施?发送带有纬度和经度的请求?
您可以使用来自 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}`,