我如何从谷歌地图获得最近的重要城镇或城市?
这可能吗?
我的用户会在地图上显示他们居住的位置,如果这不是一个大城镇或城市,我想找到它并将此信息与用户记录相关联。
知道如何做到这一点吗?
Is this possible?
I have users who will show where they live on a map, if this isn't a large town or city, i'd like to find that and associate this information with the users record.
Any idea how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不使用 GeoNames Web 服务。您可以下载完整的转储。
它以 Lat/Lng 作为参数,还有一个可选参数,称为半径(以公里为单位的距离)以及参数城市,其中:
Why not use the GeoNames Web Service. You can download the complete dump.
It takes Lat/Lng as parameters and also there is an optional parameter called radius(distance in km) as well as parameter cities where:
我意识到这是一篇旧帖子;然而,我发布我的观点是为了那些在研究中偶然发现这篇文章的人(就像我一样)的利益。
为了找到最大/最近的大城市/城镇,您需要定义“大”。
什么是大城市/城镇?这完全是主观的——我的定义与你的不同。地图服务无法决定“大”的定义。
大城市优先?假设即使您以某种方式实现了第一,您将如何确定优先顺序。一个“小”城镇 X 附近可能有 2 个大城市 - A 和 A。 B. 您会接受哪一个?
基于以上两种说法,我建议您不要这么做;但是,如果您无法避免这种情况,则需要在应用程序中添加自定义逻辑。示例:获取 25 英里内的所有位置,然后自行决定要保存的位置。
I realize this is an old post; however, I'm posting my views for the benefit of the people who stumble upon this post (like I did) in their research.
In order to find the largest/closest large city/town you would need to define 'large'.
What is a large city/town? This is completely subjective - my definition will be different from yours. A mapping service, cannot decide the definition of 'large'.
Priority of large cities? Let's say even if you somehow achieved #1, how will you prioritize. A 'small' town X might have 2 large cities close to it - A & B. Which one would you accept?
Based on the two statements above, I advice you against it; however, if it is impossible for you to avoid this, you would need to put in custom logic in your application. Example: Get all locations within 25 miles and decide for yourself what place you want to save.
我有一段时间努力寻找最好的方法来做到这一点。谷歌的API在解码坐标时似乎主要使用地址/城镇边界,这是没有帮助的。
如果您在美国,国家气象局的 API 是完美的选择。给定美国的坐标,它可以提供最近的城镇/人口普查指定地点以及该点距城镇的距离和方向。
我创建了一个基本网站来尝试 https://nearest.town/
I struggled to find the best way to do this for a while. Google's API seems to mostly use addresses/town boundaries when decoding coordinates, which is unhelpful.
If you're in the United States, the National Weather Service's API is perfect. Given coordinates in the US, it can provide the nearest town/census-designated place and the point's distance and direction from the town.
I created a basic site to try it out at https://nearest.town/