Hi Postman Pros,
Over the last few days I’ve been trying to convert a coordinate from DD (decimal degrees) to NMEA format.
the Coordinates on the Endpoint A is in LAT/LON
"latitude": 52.066177,
"longitude": 11.666398,
What the Endpoint on B want is a NMEA Sentence like:
$FRCMD,IMEI,_SendMessage,,DDMM.mmmm,N,DDMM.mmmm,E,AA.a,SSS.ss,HHH.h,DDMMYY,hhmmss.dd,valid,var=value
There are some Functions on the Web but not special in Java or Postman.
It must be something like that:
Public Enum enumLongLat
Latitude = 1
Longitude = 2
End Enum
Public Enum enumReturnformat
WithSigns = 0
NMEA = 1
End Enum
Public Function DecimalPosToDegrees(ByVal Decimalpos As Double, ByVal Type As enumLongLat, ByVal Outputformat As enumReturnformat, Optional ByVal SecondResolution As Integer = 2) As String
Dim Deg As Integer = 0
Dim Min As Double = 0
Dim Sec As Double = 0
Dim Dir As String = ""
Dim tmpPos As Double = Decimalpos
If tmpPos < 0 Then tmpPos = Decimalpos * -1 'Always do math on positive values
Deg = CType(Math.Floor(tmpPos), Integer)
Min = (tmpPos - Deg) * 60
Sec = (Min - Math.Floor(Min)) * 60
Min = Math.Floor(Min)
Sec = Math.Round(Sec, SecondResolution)
Select Case Type
Case enumLongLat.Latitude '=1
If Decimalpos < 0 Then
Dir = "S"
Else
Dir = "N"
End If
Case enumLongLat.Longitude '=2
If Decimalpos < 0 Then
Dir = "W"
Else
Dir = "E"
End If
End Select
Select Case Outputformat
Case enumReturnformat.NMEA
Return AddZeros(Deg, 3) & AddZeros(Min, 2) & AddZeros(Sec, 2)
Case enumReturnformat.WithSigns
Return Deg & "°" & Min & """" & Sec & "'" & Dir
Case Else
Return ""
End Select
End Function
Public Function AddZeros(ByVal Value As Double, ByVal Zeros As Integer) As String
If Math.Floor(Value).ToString.Length < Zeros Then
Return Value.ToString.PadLeft(Zeros, CType("0", Char))
Else
Return Value.ToString
End If
End Function
But i cant put the Math together. I will buy you 10 Coffees if you can put it together Maybe someone take the Competition