如何找到两个地址之间的距离? (Java服务器端)
我正在开发一个“社交”地理感知应用程序,价值百万美元的问题是如何列出“我的位置”“X 英里内”的一组项目,因为有数百万个应用程序可以做到这一点,我惊讶地发现只有 Google Maps API 具有免费的网络服务,更糟糕的是,只有在 Google Map 中使用时才支持它。那么我必须开发自己的距离计算器吗?有没有免费/付费服务可以让我至少将地址转换为 XY 坐标?
我确信有一个行业标准解决方案(免费或商业),但我还没有找到它
I have a "social" geographic aware application I'm developing, and the million dollar question is how do I list a set of items that are "within X miles" of "my location" since there are million applications that do that, I was surprised to find that only Google Maps API has a free web service for that, and worse, it is only supported if used within a Google Map. So do I have to develop my own distance calculator? is there any free / paid service that will allow me to at least transform an address to a XY coordinate?
I'm sure there is an industry standard solution (either free or commercial) but I'm yet to find it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实际上,Google 确实有可以在服务器上使用的网络服务方来实现这一点。
首先,您需要使用地理编码 API 将地址转换为纬度/经度坐标对。然后,您可以使用您认为合适的方式(即,如果您要存储这些内容,则针对您自己的数据库)
如果您想要查找的附近项目是 Google 可能已经知道的世界上的实际位置,您可以尝试 Google 的新 Places API,它可以为您提供特定半径内的结果。
您应该注意,从纬度/经度坐标到距离的转换确实需要一些数学,但我认为最好在本地完成(在您的应用程序运行的服务器上),而不是外包给某些外部服务器,因为它是只有数学。
谷歌搜索产生了这个。
Actually, Google does have web services you can use on the server side to achieve this.
First you'll want to use the Geocoding API to translate addresses into latitude/longitude coordinate pairs. You can then use those however you see fit (i.e. against your own database if you are storing those)
If the nearby items you want to find are actual places in the world that Google probably already knows about, you can try Google's new Places API which can give you results within a certain radius.
You should note that the translation from latitude/longitude coordinates to distances does require some math, but I think it is best done locally (on the server your application is running on) rather than being farmed out to some external server since it's only math.
Googling produced this.
如果你使用 SQL(你没有说)...我想我从 NerdDinner 项目复制了这个:
然后我使用服务器中的这些 SQL 函数,就像 C# 中的这样:
这告诉我谁(在这种情况下,人们) )在最大距离内靠近我。
这是免费版本。我认为 SQL Server 2008 可以使用地理包来执行此操作
if you're using SQL (you didn't say)... I think I copied this from the NerdDinner project:
I then use these SQL functions from the server like this in C#:
that tells me who (in this case, people) is close to me within a maximum distance.
this is the free version. I think SQL Server 2008 can perform this with a Geographic package
如果你幸运的话,你使用的是 mysql 或 postgresql,它们都是支持空间的数据库,你可以对它们执行空间查询。对于 mysql,有 空间扩展 对于 postgresql 有 postgis 。
如果您决定手动,请查看此 问题请注意。另外,我不明白 google place api 如何帮助您,因为您正在查找半径内的数据,而不是 google place 。
干杯
If you are lucky and you are using mysql or postgresql which both are spatial enabled databases you can execute spatial queries against them.For mysql there are spatial extensions and for postgresql there is postgis.
If you decide to go manual please take look at this question for heads up.Also i don't understand how the google places api can help you since you are looking your data within a radius and not google places.
Cheers
您想要“As The Crow Flies”(直线)距离,还是行驶距离/时间?
Mapquest 的 API 似乎更简单,因为您只需使用查询字符串即可。
另一种选择是 geocoder.us(如果是加拿大人,则为 .ca)
Do you want the "As The Crow Flies" (straight line) distance, or driving distance/time?
Mapquest's API seems to be easier as you can just use a query string.
Another option is geocoder.us (or .ca if Canadian)