Here’s one I made earlier!

[code]Function getDistanceWAD(myLatitude1 As Double, myLongitude1 As Double, myLatitude2 As Double, myLongitude2 As Double, Units As String, numFormat As String) As String

'Dim distance,lat1,lat2,long1,long2,r As Double

Dim R, pi, a, c, d As Double 'x, y

Dim dLat, dLong As Double

Dim Lat1, Long1, Lat2, Long2 As Double

'Dim compareDistance As String = "Distances are: "

'if Lat1 = 0 or Long1 = 0 or Lat2 = 0 or Long2 = 0 then Return “”

if myLatitude1 = 0 or myLongitude1 = 0 or myLatitude2 = 0 or myLongitude2 = 0 then

Return “”

end if

pi = 3.141592653589793

'Where R is the radius of the earth in whatever units you desire.

select case Units

case “Statute Miles”

R = 3437.74677

case “Kilometers”, “Kilometres”, “Km”, “K”, “”

R = 6371 '6371 = mead radius, 6378 = equatorial radius

case “Miles”

R = 3963

case else

R = 6371

end select

''http://www.movable-type.co.uk/scripts/latlong.html

'Lat1 = myLatitude1

'Long1 = myLongitude1

'Lat2 = myLatitude2

'Long2 = myLongitude2

''var R = 6371; // km

''var dLat = (lat2-lat1).toRad();

''var dLon = (lon2-lon1).toRad();

''var lat1 = lat1.toRad();

''var lat2 = lat2.toRad();

''var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);

''var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

''var d = R * c;

'dLat = (Lat2 - Lat1) * pi/180

'dLong = (Long2 - Long1) * pi/180

'Lat1 = Lat1 * pi/180

'Lat2 = Lat2 * pi/180

'a = Sin(dLat / 2) * Sin(dLat / 2) + Sin(dLong / 2) * Sin(dLong / 2) * Cos(Lat1) * Cos(Lat2)

'c = 2 * ATan2(Sqrt(a), Sqrt(1 - a))

'd = R * c

''Return str(R * y) + " " + Units

'compareDistance = compareDistance + "Moveable-Type = " + str(d) + " " + Units

''http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points

'Lat1 = myLatitude1

'Long1 = myLongitude1

'Lat2 = myLatitude2

'Long2 = myLongitude2

''var R = 6371; // Radius of the earth in km

''var dLat = (lat2-lat1).toRad(); // Javascript functions in radians

''var dLon = (lon2-lon1).toRad();

''var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * Math.sin(dLon/2) * Math.sin(dLon/2);

''var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

''var d = R * c; // Distance in km

'dLat = (Lat2 - Lat1) * pi/180

'dLong = (Long2 - Long1) * pi/180

'a = sin(dLat/2) * sin(dLat/2) + cos(lat1 * pi/180) * cos(lat2 * pi/180) * sin(dLong/2) * sin(dLong/2)

'c = 2 * atan2(sqrt(a), sqrt(1 - a))

'd = R * c

''Return str(d) + " " + Units

'compareDistance = compareDistance + ", versus StackOverflow1 = " + str(d) + " " + Units

'php function distance($lat1, $lon1, $lat2, $lon2) {

'$pi80 = M_PI / 180;

'$lat1 *= $pi80;

'$lon1 *= $pi80;

'$lat2 *= $pi80;

'$lon2 *= $pi80;

’

'$r = 6372.797; // mean radius of Earth in km

'$dlat = $lat2 - $lat1;

'$dlon = $lon2 - $lon1;

'$a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlon / 2) * sin($dlon / 2);

'$c = 2 * atan2(sqrt($a), sqrt(1 - $a));

'$km = $r * $c;

//echo ‘

’.$km;

'return $km;

Lat1 = myLatitude1 * pi/180

Long1 = myLongitude1 * pi/180

Lat2 = myLatitude2 * pi/180

Long2 = myLongitude2 * pi/180

dLat = Lat2 - Lat1

dLong = Long2 - Long1

a = sin(dLat / 2) * sin(dLat / 2) + cos(lat1) * cos(lat2) * sin(dLong / 2) * sin(dLong/2)

c = 2 * atan2(sqrt(a), sqrt(1 - a))

d = R * c

'compareDistance = compareDistance + ", versus StackOverflow2 = " + str(d) + " " + Units

'compareDistance = compareDistance + " (" + str(Lat1) + “,” + str(Long1) + " : " + str(Lat2) + “,” + str(Long2) + “)”

'if d > 60 then MsgBox compareDistance

if numFormat = “” then

Return str(d) + " " + Units

'Return str(r * y) + " " + Units

'Return str(ACos(Sin(Lat1) * SIN(Lat2) + COS(Lat1) * COS(Lat2) * COS(Long2 - Long1)) * r * pi/180) + " " + Units

else

Return Format(d, numFormat) + " " + Units

'Return Format(r * y, numFormat) + " " + Units

'Return Format(ACos(Sin(Lat1) * SIN(Lat2) + COS(Lat1) * COS(Lat2) * COS(Long2 - Long1)) * r * pi/180, numFormat) + " " + Units

end if

'var a = Math.sin(dLat/2) * Math.sin(dLat/2) +

'Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);

'var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

'var d = R * c;

’

'x = sin((lat2-lat1)/2) * Sin(

’

'x = (lat2 - lat1) * pi/180

'y = (long2 - long1) * pi/180

’

’

’

'x = 69.1 * (lat2 - lat1)

'y = 53 * (long2 - long1)

//Approximate distance in miles

'Return Str(Sqrt(x * x + y * y)) + " " + Units

'Excel: =ACOS(SIN(lat1)*SIN(lat2)+COS(lat1)*COS(lat2)*COS(lon2-lon1))*6371

Exception err

commonOS.doHandleExceptionWAD(err, "Method: " + CurrentMethodName)

```
'double haversine(double lat1, double lng1, double lat2, double lng2) {
'double dLat = Math.toRadians(lat2 - lat1);
'double dLon = Math.toRadians(lng2 - lng1);
'double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) *
'Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
'return 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) * 6371; // 6371 = average earth radius
```

End Function

[/code]