GPS Co-ordinate conversion to distance in VB

Sorry, bit of a newbie as far as GPS is concerned.

I'm trying to calculate the distance between two sets of GPS co-ordinates.

I can strip the data from a Serial GPS in NMEA format using the sentence RMC.

This gives me Latitude in ddmm.sssss and Longitude in dddmm.sssss.

I can store 2 of these value pairs somewhere and I then need to calculate the distance between the two.

I've looked at all of the formula's and arithmetic out there via google and on EE, but what I actually want is a function that I can just drop into my program in vb.net as some of the maths is quite complicated, and it's about 10 years since I did anything involving sin / cos functions, so 500 points are available if anyone can write the function for me !

The ideal function will take the GPS data in it's raw format and output the distance in metres and can be written in either c# or vb.net.

I'm not interested in trajectory or time, just pure distance between 2 points.

And the accuracy over distance is not a problem, as distances will not be more than 600 yards. (So you can assume that the earth is flat in your calculations!)

Something like this

Function DistanceBetweenCoOrdinates(NMEACoordLat1 as string, NSIndicator1 as string, NMEACoordLong1 as string, WEIndicator1 as string, NMEACoordLat2 as string, NSIndicator2 as string, NMEACoordLong2 as string, WEIndicator2 as string) as Double

' **** Insert code here ****


End Function



LVL 3
WillEastburyAsked:
Who is Participating?
 
ee_ai_constructCommented:
Closed, 500 points refunded.
ee_ai_construct
Community Support Moderator
replacement part #xm34
0
 
WillEastburyAuthor Commented:
Cribbed a few bits from different sites and hacked them around and came up with this :-

    Private Function Geo2PointDistanceFormula2(ByVal Lat1 As Double, ByVal Lon1 As Double, ByVal Lat2 As Double, ByVal Lon2 As Double) As Double

        Dim a, b, c As Double
        Const PI = 3.14159265358979
        Const RadiusEarth = 6371000

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

        a = Cos(Lat1 * PI / 180) * Cos(Lat2 * PI / 180) * Cos(Lon1 * PI / 180) * Cos(Lon2 * PI / 180)
        b = Cos(Lat1 * PI / 180) * Sin(Lon1 * PI / 180) * Cos(Lat2 * PI / 180) * Sin(Lon2 * PI / 180)
        c = Sin(Lat1 * PI / 180) * Sin(Lat2 * PI / 180)

        If (a + b + c) >= 1 Or (a + b + c) <= -1 Then
            Return 0
        Else
            Return Acos(a + b + c) * RadiusEarth * 1.0936 ' Distance will be in yards

        End If

end function
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.