# [calc_distance]

 Link calc_distance Author Tim Taplin Category Utility Version 9.x License Public Domain Posted 26 Mar 2013 Updated 26 Mar 2013 More by this author...

#### Description

This tag will calculate the distance between two points defined by latitude and longitude in miles with an optional parameter to return kilometers. Internally uses an implementation of the Haversine formula to account for curvature of the earth.

#### Sample Usage

```local('curr_coords' = pair(51.027576,-114.058891))
local('dest' = pair(51.011760, -114.066260))
calc_distance(
#curr_coords->first,
#curr_coords->second,
#coord->first,
#coord->second
)

Returns:
1.172478```

#### Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

```define calc_distance(curr_lat::decimal, curr_lon::decimal, dest_lat::decimal, dest_lon::decimal, meas='m') => {
//provide current location and destination as latitude and longitude as decimal
//optionally provide meas value of 'k' to return kilometers

local(distance = (
(
(
(#curr_lat * pi / 180)->sin * (#dest_lat * pi / 180)->sin
+ (#curr_lat * pi / 180)->cos * (#dest_lat * pi / 180)->cos *
((#curr_lon - #dest_lon) * pi / 180)->cos
)->acos * 180 / pi
) * 60 * 1.1515
))
#meas == 'k' ? return #distance*1.609344 | return #distance
//return #distance
}```

26 Mar 2013, Steve Piercy

http://www.lassosoft.com/tagswap/detail/lp_math_GPSdistance

26 Mar 2013, Steve Piercy

Distance between two US Zip Codes

To calculate the distance between two US Zip Codes, see:
http://www.stevepiercy.com/lasso_stuff/zipdist/distance.lasso

You can download the source and the associated ZIP code database that maps ZIP codes to their latitude and longitude.