简体   繁体   English

使用 react-leaflet 从坐标获取地址

[英]Get address from coordinates with react-leaflet

Using react-leaflet, I want to get the location address information from coordinates.使用react-leaflet,我想从坐标中获取位置地址信息。

I found a working example of a similar behavior: here我找到了一个类似行为的工作示例: here

However it seems it doesn't work with my version of react-leaflet.但是它似乎不适用于我的 react-leaflet 版本。 Also I don't even need it to work with onClick events, just get the address on page load so i can populate a form field.此外,我什至不需要它来处理 onClick 事件,只需在页面加载时获取地址,这样我就可以填充表单字段。

Any push in the right direction would be most helpful.任何朝着正确方向的推动都会是最有帮助的。

You are looking after a reverse geocoding service.您正在寻找反向地理编码服务。 You can start by looking into Nominatim it is free and it is what they use in the example.您可以从查看Nominatim开始,它是免费的,并且是他们在示例中使用的。 However remember to read the usage policy, it is not meant for heavy use.但是请记住阅读使用政策,它不适合大量使用。 If you know that you will make a lot i requests each second you should look for a paid alternative.如果您知道自己每秒都会赚很多钱,那么您应该寻找付费的替代方案。

Would recommend to build your own service that can take coordinates and pass that to the api, relaying on a package. eg建议构建您自己的服务,可以获取坐标并将其传递给 api,中继 package。例如

I have a graphql query hook that I pass latLng that I get from leaflet -> pass it through my backend -> Nominatim.我有一个 graphql 查询挂钩,我传递了从 leaflet 获得的 latLng -> 通过我的后端 -> Nominatim。

const { data, fetching, error } = useReverseGeo(latLng);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM