View Single Post
  #1 (permalink)  
Old 05-06-2008, 02:56 PM
abastien abastien is offline
Newbie
 
Join Date: Mar 2008
Posts: 6
Post Calculating distance

Here is some sample code to calculate distance between two points:

Code:
Sub getDistanceKM(lat1, long1, lat2, long2)

	DEGREES_TO_RADIANS = (cPI / 180.0)
	EARTH_RADIUS = 6371.0
	
	rlat1 = DEGREES_TO_RADIANS * lat1
	rlong1 = DEGREES_TO_RADIANS * long1
	rlat2 = DEGREES_TO_RADIANS * lat2
	rlong2 = DEGREES_TO_RADIANS * long2
	
	'	There is no real reason To break this lot into 
	'	4 statements but I just feel it's a little more 
	'	readable.
	p1 = Cos(rlat1) * Cos(rlong1) * Cos(rlat2) * Cos(rlong2)
	p2 = Cos(rlat1) * Sin(rlong1) * Cos(rlat2) * Sin(rlong2)
	p3 = Sin(rlat1) * Sin(rlat2)

	ret = p1 + p2 + p3
	If ret = 1 Then Return 0
	
	ret = ACos(ret)
	ret = ret * EARTH_RADIUS
	
	Return ret
	
End Sub
Can we add this to the gps.dll?
Reply With Quote