有哪些现有服务可用于计算两个地址之间的距离?

发布于 2024-07-06 01:21:17 字数 757 浏览 9 评论 0原文

我想实现一种方法来显示按与给定地址的邻近程度排序的存储地址列表。

列表中的地址将存储在数据库表中。 单独的部分有单独的字段(我们有邮政编码、城市名称等字段),因此它不仅仅是一个巨大的 varchar。 这些是用户输入的,并且由于系统的性质可能并不总是完整的(有些可能缺少邮政编码,有些可能只包含城市和州)。

虽然这是针对 Intranet 应用程序的,但我在使用外部资源(包括访问互联网 Web 服务等)时没有任何问题。 实际上,我更喜欢这样做,而不是自己动手,除非自己做起来很简单。 如果谷歌或雅虎! 已经提供免费服务,我非常愿意去看看。 关键词是它必须是免费的,因为我不能随意为此功能在该项目中引入任何额外费用,因为可以说它已经是一项额外的“福利”。

我的想法就像许多砖块和砖块一样。 砂浆店有“查找位置”功能。 将其显示在一个简单的表格中,并进行适当排序并显示距离(例如,英里)是很棒的。 显示地图混搭甚至更酷,但我绝对可以接受只返回距离并处理所有后续显示和排序。

简单距离算法的问题在于数据的性质。 由于地址的全部或部分可能是未定义的,因此我没有任何方便的东西,例如纬度/经度坐标。 另外,即使我要求提供邮政编码,90% 的地址也可能具有相同的五个邮政编码。

虽然它不需要非常快,但正如我们所知,由于延迟而需要超过七秒才能显示在页面上的任何内容可能对于普通用户来说等待时间太长。 如果这样的假设服务支持一次发送一批地址而不是一次查询一个地址,那就太好了。 不过,我认为地址列表总数不会超过 50 个(如果有的话)。

I'd like to implement a way to display a list of stored addresses sorted by proximity to a given address.

Addresses in the list will be stored in a database table. Separate parts have separate fields (we have fields for postal code, city name, etc.) so it is not just a giant varchar. These are user-entered and due to the nature of the system may not always be complete (some may be missing postal code and others may have little more than city and state).

Though this is for an intranet application I have no problems using outside resources including accessing internet web services and such. I'd actually prefer that over rolling my own unless it would be trivial to do myself. If Google or Yahoo! already provides a free service, I'm more than willing to check it out. The keyword is it must be free, as I'm not at liberty to introduce any additional cost onto this project for this feature as it is already a bonus "perk" so to speak.

I'm thinking of this much like many brick & mortar shops do their "Find a Location" feature. Showing it in a simple table sorted appropriately and displaying distance (in, say, miles) is great. Showing a map mash-up is even cooler, but I can definitely live with just getting the distance back and me handling all of the subsequent display and sorting.

The problem with simple distance algorithms is the nature of the data. Since all or part of the address can be undefined, I don't have anything convenient like lat/long coords. Also, even if I make postal codes required, 90% of the addresses will probably have the same five postal codes.

While it need not be blisteringly fast, anything that takes more than seven seconds to show up on the page due to latency might be too long for the average user to wait, as we know. If such a hypothetical service supports sending a batch of addresses at once instead of querying one at a time, that'd be great. Still, I should not think the list of addresses would exceed 50 total, if that many.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(8

成熟稳重的好男人 2024-07-13 01:21:17

我们在我的公司做过的一件事是欺骗并使用邮政编码的纬度/经度(大致是邮政编码区域的中心)。 它并不完美,但对于那些在 y 类型搜索的 n 英里内找到我 x 的人来说已经足够接近了。 当地址清理服务无法识别地址时,这尤其有用。

在某些时候,我遇到了一个免费的邮政编码到纬度/经度查找表,可用于此近似值。 抱歉,我不再有此链接。

One thing we've done at my company is to cheat and use the latitude/longitude of the zip code (Roughly the center of the zip code area). It's not perfect, but it's close enough for those find me x within n miles of y types of searches. This is especially helpful when the addresses can't be recognized by address cleaning services.

At some point I came across a free zip code to latitude/longitude lookup table to use in this approximation. I'm sorry I don't have the link to this any more.

你好,陌生人 2024-07-13 01:21:17

GoogleYahoo! 都免费提供地理编码服务。 您可以使用Haversine 公式在 .NET 或 SQL 中实现)。 这两种服务都可以让您进行部分搜索(仅邮政编码,仅城市),并让您知道其结果的精确度(以便您可以排除没有有意义信息的位置,尽管雅虎提供了比谷歌更精确的信息)。

Google and Yahoo! both provide geocoding services for free. You can calculate distance using the Haversine formula (implemented in .NET or SQL). Both services will let you do partial searches (zip code only, city only) and will let you know what the precision of their results are (so that you can exclude locations without meaningful information, though Yahoo! provides more precision info than Google).

杀お生予夺 2024-07-13 01:21:17

由于其使用条款,Google Maps API 对您没有任何好处。 但是,雅虎提供了 REST 服务,用于将地址转换为经/纬度坐标,然后您可以使用它来计算距离。 其此处

The Google Maps API is no good to you due to their terms of use. However, Yahoo offer a REST service for turning addresses into Long/Lat coordinates, which you could then use to calculate distances. Its here.

青萝楚歌 2024-07-13 01:21:17

要求他们输入邮政编码,然后创建一个数据库表,将邮政编码映射到纬度/经度对(或在线查找)。 我不知道你工作的地方怎么样,但在这里,邮政编码可以具体到几米,所以应该足够精确。 然后使用此方法来计算两个邮政编码之间的距离:

public static double distance(double lat1, double lon1, double lat2, double lon2, char unit)
{
  double theta = lon1 - lon2;
  double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) +
    Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));
  dist = Math.Acos(dist);
  dist = rad2deg(dist);
  dist = dist * 60 * 1.1515;
  if (unit == 'K')
  {
    dist = dist * 1.609344;
  }
  else if (unit == 'N')
  {
    dist = dist * 0.8684;
  }
  return (dist);
}

private static double deg2rad(double deg)
{
  return (deg * Math.PI / 180.0);
}

private static double rad2deg(double rad)
{
  return (rad / Math.PI * 180.0);
}

与地理编码服务相比,使用您自己的代码的优点是,您可以对数据进行一系列更有趣的计算,并将数据与数据一起存储在数据库中。

Require them to enter a ZIP code, then create a database table mapping ZIP code to latitude/longitude pairs (or find one online). I don't know how it is where you work but over here, ZIP code can be specific to several meters, so that should be precise enough. Then use this method to calculate the distance between two ZIP codes:

public static double distance(double lat1, double lon1, double lat2, double lon2, char unit)
{
  double theta = lon1 - lon2;
  double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) +
    Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));
  dist = Math.Acos(dist);
  dist = rad2deg(dist);
  dist = dist * 60 * 1.1515;
  if (unit == 'K')
  {
    dist = dist * 1.609344;
  }
  else if (unit == 'N')
  {
    dist = dist * 0.8684;
  }
  return (dist);
}

private static double deg2rad(double deg)
{
  return (deg * Math.PI / 180.0);
}

private static double rad2deg(double rad)
{
  return (rad / Math.PI * 180.0);
}

The advantage of using your own code over a geocoding service is that you can then do a bunch more interesting calculations against the data as well as storing stuff alongside it in your db.

凉城已无爱 2024-07-13 01:21:17

你不能只使用谷歌地图 API 来获取距离并在你这边对它们进行排序吗?

http://code.google.com/apis/maps/

Can't you just use google maps API to get the distances and sort them on your side?

http://code.google.com/apis/maps/

蓝梦月影 2024-07-13 01:21:17

我建议调查谷歌地图 API。

它需要你有一个外部连接(并且可以将数据分流到网络服务),但它提供了你所需要的,即通过询问两点之间的路线并获取距离它。

路线 API 的 API 参考

I'd suggest investigating the google maps API.

It would require you to have an external connection (and for it to be alright to shunt the data over it to a web service) but it provides what you require, namely the distance by asking for a route between 2 points and getting the distance from it.

API reference of the directions API

淡看悲欢离合 2024-07-13 01:21:17

查看此网站:http://geocoder.us/help/utility.shtml

您可以处理记录,每 15 秒 1 次,如下所示:
http://geocoder.us/service/distance?zip1=95472&zip2= 94305

他们还有无时间限制的订阅服务

Check out this website: http://geocoder.us/help/utility.shtml

You can process records, 1 per 15 seconds like this:
http://geocoder.us/service/distance?zip1=95472&zip2=94305

They also have a subscription service without the time limit

待"谢繁草 2024-07-13 01:21:17

其他人已经在 Daft Logic 上完成了此操作(编辑:错字)。 他们将 Google Maps API 与大圆公式结合使用。 我认为实施起来并不困难。

更新:实际上,您只需要从您最喜欢的提供商处获取坐标,然后使用您的代码进行计算即可。 当用户提供他们的位置时,您可以预加载商店的坐标 - 您甚至可以使用它进行验证。 然后,当发出请求时,您只能查找客户的位置。

Someone else has done it already at Daft Logic (edit: typo). They use Google Maps API with the Great-circle formula. I don't think it's hard to implement.

Update: Practically, you only need to get the coordinates from your favourite provider, then do the calculation with your code. You can preload the shops' coordinates, when users provide their location - you can even use this for validation. Then, when the request is made, you can only lookup the customer's location.

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