从 Google Maps API 构建交叉路口
问题:
我尝试使用 Google Maps API V3 将纬度/经度反向地理编码为最近的街道交叉口。另外,目前,这不必非常准确——因为我只是试图匿名化地址,而不是提供方向。
我发现地理编码结果数据包含地址组件类型< /a> 的“Intersection”,但这在返回结果中似乎根本不一致——而且更常见的是不是空白。
我还做了一些寻找构建这个的最佳方法,禁止直接从谷歌获取它,我见过的最接近的是: 如何通过 Google Maps API 找到最近的交叉路口?,这并不能真正解决我的问题。鉴于此,我提出了自己的解决方案,并希望得到一些意见、优化、建设性批评或完全其他选择。
我的暂定解决方案:
在尝试使用 API 后,我决定尝试一下以下算法(仅供参考,这是在控制台应用程序中用 C# 编写的):
我获取一个地址并将其解析为纬度/经度。
然后我从 坐标——按照城市街区的顺序(根据您的情况调整距离) 纬度)并获取点之间的步行方向。我对最多四个方向执行此操作 - 因此第一个修改是保持纬度相同,但减去一些经度。然后,下一个修改将是保留纬度并添加一些经度等。
在获得方向后,我解析结果并检查开始 和结束地址。如果它们不同,我会提取街道名称 并将它们视为“交叉点”(尽管有时这 结果是平行的街道——再次只是想得到一个大概)。
如果我没有找到两条不同的街道,我会扩大最终目的地的距离并重复该过程。
到目前为止,这工作得很好,但显然,无论是在时间方面还是在用完我分配的查询限制方面,这都是一个昂贵的过程。另外,我检查了 API 服务条款,只要包含他们的免责声明并在 Google 地图上显示结果,我认为就可以了。
我向社区提出的问题是:
如何提高算法的效率?具体来说,在 我调用API的次数(实现代码不是 问题)
是否有另一种完全使用 Google Maps API 来完成此操作的方法? 在上面提到的SO问题中< /a>,解决方案是循环 超过建筑物数量。我不确定这到底意味着什么——所以任何 如果能澄清一下就好了。
如上所述,我不认为这违反了服务条款 - 但我错了吗?
是否有其他基于 Web 的 API 可以更好地满足我的需求? 也许是 Bing,或者其他一些提供商?
非常感谢您的帮助。
更新: 我已经达到了当天的查询限制,因此我今天无法针对 Google 测试任何建议,但我仍然愿意使用不同的 API。谢谢。
Problem:
I am trying to reverse geocode a lat/long into a closest street intersection using Google Maps API V3. Also, for now, this doesn't have to be super accurate-- as I am just trying to anonymize an address as opposed to providing directions.
I have seen that the Geocoding Results data contains an Address Component Type of "Intersection", but this doesn't seem to be consistent at all in the return results-- and is more often that not blank.
I have also done some looking on SO for the best way to construct this barring getting it from Google directly, and the closest I have seen is: How can I find the nearest intersection via the Google Maps API?, which doesn't really resolve my issue. In light of this I have come up with my own solution, and would like some opinions, optimizations, constructive criticism, or other options entirely.
My Tentative Solution:
After playing around with the API, I decided to give the following algorithm a shot (just for context, this is written in C# within a console app):
I take an address and resolve that into a lat/long.
I then add or subtract a certain amount of lat or long from the
coordinate-- on the order of a city block (a distance which is adjusted given your
latitude) and get walking directions between the points. I do this for up to all four directions-- so the first modification would be to keep the latitude the same but subtract some longitude. Then the next modification would be to keep the latitude and add some longitude, etc.After getting the directions, I parse the results and check the start
and end address. If they are different, I pull out the street names
and treat them as an "intersection" (even though sometimes this
results in parallel streets-- again just trying to get a ballpark).If I don't find two different streets, I widen the distance of the end destination and repeat the process.
So far this working well enough, but obviously it is an expensive process both in terms of time, and in using up my allotted query limit. Also, I checked the API terms of service, and as long as I include their disclaimer and display the results on a Google Map I think that I am ok.
My questions for the community are:
How can I improve the efficiency of the algorithm? Specifically, in
the number of times I call the API (the implementation code is not a
problem)Is there another way entirely to do this using the Google Maps API?
In the SO question referred to above, the solution was to loop
over building numbers. I am not sure exactly what that means-- so any
clarification would be great.As referred to above, I do not believe this is breaking the terms of service-- but am I mistaken?
Is there another web-based API to use that may meet my needs better?
Perhaps Bing, or some other provider?
Thanks a lot for any help.
UPDATE:
I have run into my query limit for the day, so I won't be able to test any suggestions against Google today, but I am also still open to using a different API. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老问题,但由于原始发帖者表示他们对 Google 以外的解决方案持开放态度,Geonames 为美国提供了一个 Web API,请参阅 GeoNames Web 服务概述 和 http://www.geonames.org/maps/us-reverse-geocoder.html#findNearestIntersection
Old question, but since the original poster stated they were open to solutions other than Google, Geonames has a web API for this for the U.S. See GeoNames WebServices overview and http://www.geonames.org/maps/us-reverse-geocoder.html#findNearestIntersection