邮政编码距离计算器

我有一个电子表格的地址,我需要计算所有的邮政编码和我的邮政编码之间的距离。 我对所使用的方法相当灵活,但我希望某种Web服务或mathalgorithm。 美国地址只。 基本上我需要喂2个邮政编码,并走出他们之间的距离。

我愿意使用Excel公式或VBA,如果需要,我甚至可以用C#.net编写代码。

你将如何去计算这些距离?

实际上这很简单。 下载邮政编码的GPS坐标数据库,有大量的网站有这个数据可供下载。 他们将列出邮政编码中心的坐标。

用公式计算最短距离(例如: http : //www.movable-type.co.uk/scripts/latlong.html )

你可以使用经度和纬度。

Excel中:

=IF(SIN(Lat1) * SIN(Lat2) + COS(Lat1) * COS(Lat2) * COS(Long1 - Long2) > 1, RadiusofEarth * ACOS(1), RadiusofEarth * ACOS(SIN(Lat1) * SIN(Lat2) + COS(Lat1) * COS(Lat2) * COS(Long1-Long2))) 

VB.net导入System.Math

 Private Function Distance(ByVal lat1 As Double, ByVal lon1 As Double, ByVal lat2 As Double, ByVal lon2 As Double, ByVal unit As String) As Double Dim theta As Double = lon1 - lon2 Dim dist = System.Math.Sin(deg2rad(lat1)) * System.Math.Sin(deg2rad(lat2)) + System.Math.Cos(deg2rad(lat1)) * System.Math.Cos(deg2rad(lat2)) * System.Math.Cos(deg2rad(theta)) dist = System.Math.Acos(dist) dist = rad2deg(dist) dist = dist * 60 * 1.1515 Select Case unit Case "K" dist = dist * 1.609344 Case "N" dist = dist * 0.8684 End Select Return dist End Function 

其他有用的链接(第一个也提到了VBA的替代品)

ExcelLatLong (也提到VBA的替代品)

通过经纬度拉伸查找

VBA讨论

编辑:由于评论讨论添加的链接

更多信息(Excel公式)