## Dave Heavy Industries - A journal of tech-findings and ramblings

The earth isn’t flat. Sometimes you feel like over engineering a simple problem just because you can.

Late last year I put together a mobile web interface and used google maps for a store locator. I also had to use ASP Classic. In the mids of this it struck me that a customer might find they were a few meters off from the actual distance from their current position, to what I’m reporting. Clearly this just won’t do -so I re-worked it to compensate….in ASP CLASSIC, where most of the math is non existent.

enjoy!

``````Const M_PI = 3.14159265358979323846
Function Log2(X)
Log2 = Log(X) / Log(2)
End Function
deg2rad = x * M_PI / 180
end function
rad2deg = x * 180 / M_PI
end function
Function atan2(ys,xs)
Dim theta
If xs <> 0 Then
theta = Atn(ys / xs)
If xs < 0 Then
theta = theta + pi
End If
Else
If ys < 0 Then
theta = 3 * pi / 2 '90
Else
theta = pi / 2 '270
End If
End If
atan2 = theta
End Function
function distance_between(a_lat,a_lon,b_lat,b_lon)
dim dLat, dLon