tags:

views:

198

answers:

1

Hi, How can I parse GPS which is string coordinates (like 33°58'9"S 18°35'51"E) to degrees e.g. double types to be used for calculating the distance between to GPS coordinates.

C# programming language, the user will enter the GPS coordinates as a string (samples above).

+1  A: 

As has already been stated in the comments section

  1. split the string on the symbols and take the degrees, minutes and seconds parts individually.
  2. The degrees and minutes will be integers, the seconds field may have a fractional part and require a floating point input capability. It depends upon your positional accuracy/resolution.
  3. Calculate the value in degrees DEG + (MIN/60) + (SEC/3600) // Typecasts ignored
  4. Apply the sign to the result based on the N,S,E,W. By convention N and E are positive, S and W are negative

You will now want to calculate the distance between points which will probably require the conversion of your coordinates from degrees to radians to allow the use of the standard trig libraries.

distance = 2*asin(sqrt((sin((lat1-lat2)/2))^2 + 
                  cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
Ian