从 Google Maps API 构建交叉路口

发布于 2024-12-01 14:39:07 字数 1701 浏览 1 评论 0原文

问题

我尝试使用 Google Maps API V3 将纬度/经度反向地理编码为最近的街道交叉口。另外,目前,这不必非常准确——因为我只是试图匿名化地址,而不是提供方向。

我发现地理编码结果数据包含地址组件类型< /a> 的“Intersection”,但这在返回结果中似乎根本不一致——而且更常见的是不是空白。

我还做了一些寻找构建这个的最佳方法,禁止直接从谷歌获取它,我见过的最接近的是: 如何通过 Google Maps API 找到最近的交叉路口?,这并不能真正解决我的问题。鉴于此,我提出了自己的解决方案,并希望得到一些意见、优化、建设性批评或完全其他选择。

我的暂定解决方案:

在尝试使用 API 后,我决定尝试一下以下算法(仅供参考,这是在控制台应用程序中用 C# 编写的):

  • 我获取一个地址并将其解析为纬度/经度。

  • 然后我从 坐标——按照城市街区的顺序(根据您的情况调整距离) 纬度)并获取点之间的步行方向。我对最多四个方向执行此操作 - 因此第一个修改是保持纬度相同,但减去一些经度。然后,下一个修改将是保留纬度并添加一些经度等。

  • 在获得方向后,我解析结果并检查开始 和结束地址。如果它们不同,我会提取街道名称 并将它们视为“交叉点”(尽管有时这 结果是平行的街道——再次只是想得到一个大概)。

  • 如果我没有找到两条不同的街道,我会扩大最终目的地的距离并重复该过程。

到目前为止,这工作得很好,但显然,无论是在时间方面还是在用完我分配的查询限制方面,这都是一个昂贵的过程。另外,我检查了 API 服务条款,只要包含他们的免责声明并在 Google 地图上显示结果,我认为就可以了。

我向社区提出的问题是:

非常感谢您的帮助。

更新: 我已经达到了当天的查询限制,因此我今天无法针对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩余の解释 2024-12-08 14:39:07

老问题,但由于原始发帖者表示他们对 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文