Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

GPS Co-ordinate conversion to distance in VB

Posted on 2006-05-24
Medium Priority
874 Views
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

0
Question by:WillEastbury

LVL 3

Author Comment

ID: 16852733
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

' 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

Accepted Solution

ee_ai_construct earned 0 total points
ID: 16856130
Closed, 500 points refunded.
ee_ai_construct
Community Support Moderator
replacement part #xm34
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll