Lasso Soft Inc. > Home

[calc_distance]

Linkcalc_distance
AuthorTim Taplin
CategoryUtility
Version9.x
LicensePublic Domain
Posted26 Mar 2013
Updated26 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
}

Comments

26 Mar 2013, Steve Piercy

Related tags lp_math_GPSdistance lp_math_GPSradius

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

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

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.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft