Question

usually, I use 14.some numbers and 121.some numbers as map coordinates on my app.
While I am working on a new module that sends different gps logs, I get this coordinates:

1434.7906
12103.5434

at first I thought my app is not routing, but then I saw that the coordinates given is off, or bluntly, in wrong format (decimal places moved to the right twice). Is there something wrong with the module? Or is there a formula to convert it to normal coordinates?

EDIT UPDATE: I discovered that the above format is on 14D 34M 7906S--(got this from the link below)
Which eventually, gave me a problem. changed the title
How can I convert it to Decimal Form?

  • Answer : something like split it after to chars. --> My first thought, but..

How about 12103? I need it to be 121 and 03 - which needed to split after 3 chars. Thus I can't control the burst of string to even to that. Need help! thanks

At the end of the day, I need those 2 above to be converted to this: 14.5798433°, 121.0590567°
Calc Source

enter image description here

Was it helpful?

Solution

Providing you have leading zeroes (matters for other parts of the world), longtitudes are always 3 digits (0-180) and latitudes are 2 digits (0-90).

The notation only makes sense if it is about degrees + decimal minutes, ie

1434.7906  = 14° + 34.79060' = 14 + (34.79060 / 60) °  

In C#, untested:

string lat = ..., lon = ...;

double la = double.Parse(lat.Substring(0, 2)) + double.Parse(lat.Substring(2)) / 60.0;
double lo = double.Parse(lon.Substring(0, 3)) + double.Parse(lon.Substring(3)) / 60.0;

OTHER TIPS

I am not familiar with coordinates but it looks like the first of your value before the period have to be 5 digits and the second value 4 digits. So I would split first on the period (full stop) character. Then if the first value is 4 digits pad to 5 by placing a 0 in front. Then split on position so you have 014 and 34 which would then become 14 and 34. et al.

by shell to split the number

$     echo 1434 |sed 's/\(..\)$/ \1/'
14 34

$     echo 12103 |sed 's/\(..\)$/ \1/'
121 03

If you need handle the whole number with expect output:

$     echo 1434.7906 |sed -r 's/(.*)(..)\.(.*)/\1Degress, \2Minutes \3Seconds/'
14Degress, 34Minutes 7906Seconds

Note that longitude and latitude can be negative. Here is a function that is messy in type conversion:

    Function DecDegree(dd_mm_decmm As String) As String
      Dim deg As String = dd_mm_decmm.Substring(0, dd_mm_decmm.IndexOf(".") - 2)
      Dim mm_dec As String = dd_mm_decmm.Substring(dd_mm_decmm.IndexOf(".") - 2)
      Dim decDegrees As Double = CDbl(deg) + (CDbl(mm_dec / 60) * If(CDbl(deg) < 0, -1, 1))
      Return FormatNumber(decDegrees, 6)
    End Function

The split is based on the location of the decimal point. The math for the minutes conversion checks to see if it needs to add or subtract. The func returns 6 decimal points which is plenty for any but survey grade GPS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top