GPS Co-ordinate conversion to distance in VB

Posted on 2006-05-24
Last Modified: 2009-02-13
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 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

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

Question by:WillEastbury
    LVL 3

    Author Comment

    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
                Return Acos(a + b + c) * RadiusEarth * 1.0936 ' Distance will be in yards

            End If

    end function

    Accepted Solution

    Closed, 500 points refunded.
    Community Support Moderator
    replacement part #xm34

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now