计算之间的距离2城市 [英] Calculating Distance Between 2 Cities

查看:195
本文介绍了计算之间的距离2城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算两个城市之间的距离?

How do you calculate the distance between 2 cities?

推荐答案

如果你需要采取的地球曲率考虑在内,大圆的距离就是你在找什么。维基百科文章大概会解释如何公式工作比我更好的工作,另外还有<一个HREF =htt​​p://williams.best.vwh.net/avform.htm>这个航空公式页,涵盖了进入更多的细节。

If you need to take the curvature of the earth into account, the Great-Circle distance is what you're looking for. The Wikipedia article probably does a better job of explaining how the formula works than me, and there's also this aviation formulary page that covers that goes into more detail.

该公式只是拼图的第一部分,不过,如果你需要,使这项工作对任意的城市,你需要一个位置数据库,从获取纬度/长。幸运的是,你可以得到这个免费从 Geonames.org ,虽然有可用的商业分贝的(问谷歌)。因此,在一般情况下,查找你想要的两个城市,得到了纬度/长协orinates并将其插入公式作为维基百科的成功范例

The formulas are only the first part of the puzzle though, if you need to make this work for arbitrary cities, you'll need a location database to get the lat/long from. Luckily you can get this for free from Geonames.org, although there are commercial db's available (ask google). So, in general, look up the two cities you want, get the lat/long co-orinates and plug them into the formula as in the Wikipedia Worked Example.

其他建议:

  • 对于一个完整的商业解决方案, 有 PC米勒中所使用 许多货运公司 计算运费。
  • 请调用谷歌地图(或其他方式)的API。如果你需要每天做很多的要求,考虑缓存服务器上的结果。
  • 同样的很重要是要考虑城市,郊区,乡镇建立一个对​​等的数据库等等,如果你认为你会永远需要将数据分组。这变得非常复杂,虽然,你可能找不到一个尺寸适合所有的你的问题的解决方案。
  • For a full commercial solution, there's PC Miler which is used by many trucking companies to calculate shipping rates.
  • Make calls to the Google Maps (or other) api. If you need to do many requests per day, consider caching the results on the server.
  • Also very important is to consider building an equivalence database for cities, suburbs, towns etc. if you think you'll ever need to group your data. This gets really complicated though, and you may not find a one-size-fits-all solution for your problem.

最后但并非最不重要的,乔尔写了一篇关于这个问题的文章而回,所以在这里你走:新特性:求职

Last but not least, Joel wrote an article about this problem a while back, so here you go: New Feature: Job Search

这篇关于计算之间的距离2城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆