I have a JavaScript function which will tell you the distance between 2 points using latitude/longitude

Lat/lon are passed as numbers, like 41.39733579 and -90.33258726.

I'm trying to convert to PB, but it doesn't work.

I have:

what am I doing wrong?

For context, you can do an online test here

Code:

// figure distance between 2 lat/lon points function distance(lat1, lon1, lat2, lon2, unit) { if ((lat1 == lat2) && (lon1 == lon2)) { return 0; } else { var radlat1 = Math.PI * lat1/180; var radlat2 = Math.PI * lat2/180; var theta = lon1-lon2; var radtheta = Math.PI * theta/180; var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta); if (dist > 1) { dist = 1; } dist = Math.acos(dist); dist = dist * 180/Math.PI; dist = dist * 60 * 1.1515; // 'M' - miles is default if (unit=="K") { dist = dist * 1.609344 } if (unit=="N") { dist = dist * 0.8684 } if (unit=="F") { dist = dist * 5280 } return dist; } }

I'm trying to convert to PB, but it doesn't work.

I have:

Code:

pi = 3.141592653589793 ' returns distance in rounded off feet Function distance(lat1 As Double, lon1 As Double, lat2 As Double, lon2 As Double) As Long Local radlat1 As Double Local radlat2 As Double Local theta As Double Local radtheta As Double Local dist As Double If ((lat1 = lat2) And (lon1 = lon2)) Then Function = 0 Exit Function Else radlat1 = pi * lat1/180 radlat2 = pi * lat2/180 theta = lon1-lon2 radtheta = pi * theta/180 dist = Sin(radlat1) * Sin(radlat2) + Cos(radlat1) * Cos(radlat2) * Cos(radtheta) If (dist > 1) Then dist = 1 End If dist = arccos(dist) dist = dist * 180/pi dist = dist * 60 * 1.1515 Function=dist*5280 ' return in feet End If End Function Function arccos(v As Double) As Double Function = pi / 2 - Atn(v / Sqr(1 - v * v)) End Function

what am I doing wrong?

For context, you can do an online test here

## Comment