H

#### Hugh Janus

different results when running on the Windows Mobile 5 emulator and a

real Windows Mobile 6 device? I am trying to find out the distance in

metres between 2 GPS points. It works correctly on the emulator but

the WM6 device gives bizarre values!

Values given are: WM5: 0.84912711886472536 & WM6: 50481

Call to function: CalculateDistance(40.44717, -3.63763, 40.44717,

-3.63762)

Please help as I am totally lost! I am using Visual Studio 2005 + VB

with the 2.0 compact framework.

TIA

Private Function CalculateDistance(ByVal Lat1 As Double, ByVal

Lon1 As Double, ByVal Lat2 As Double, ByVal Lon2 As Double) As Integer

Dim a, b, c As Double

' 1 Degree is 69.096 miles, 1 mile is 1609.34 m

a = Math.Cos(Lat1 * Math.PI / 180) * Math.Cos(Lat2 * Math.PI /

180) * Math.Cos(Lon1 * Math.PI / 180) * Math.Cos(Lon2 * Math.PI / 180)

b = Math.Cos(Lat1 * Math.PI / 180) * Math.Sin(Lon1 * Math.PI /

180) * Math.Cos(Lat2 * Math.PI / 180) * Math.Sin(Lon2 * Math.PI / 180)

c = Math.Sin(Lat1 * Math.PI / 180) * Math.Sin(Lat2 * Math.PI /

180)

If (a + b + c) >= 1 Or (a + b + c) <= -1 Then

CalculateDistance = 0

Else

CalculateDistance = Convert.ToInt32(Math.Acos(a + b + c) *

6371000)

End If

End Function