ConvertToMinutes

cmartins

Member
Licensed User
Longtime User
Erel,


I am using ConvertToMinutes like this:

lat = ConvertToMinutes(-22.02)

return:
"-22:1,2"

This should not be like this:
"-22:01,2"
 

kickaha

Well-Known Member
Licensed User
Longtime User
Erel,

I think he is using the ConvertToMinutes in the GPS library, it is a member of the Location type.

not got access to a computer to try it.
 
Upvote 0

cmartins

Member
Licensed User
Longtime User
thats it


I am creating a NMEA Log without checksums:

RMC - NMEA has its own version of essential gps pvt (position, velocity, time) data. It is called RMC, The Recommended Minimum, which will look similar to:

$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A

Where:
RMC Recommended Minimum sentence C
123519 Fix taken at 12:35:19 UTC
A Status A=active or V=Void.
4807.038,N Latitude 48 deg 07.038' N
01131.000,E Longitude 11 deg 31.000' E
022.4 Speed over the ground in knots
084.4 Track angle in degrees True
230394 Date - 23rd of March 1994
003.1,W Magnetic Variation
*6A The checksum data, always begins with *




My code:

Sub GPS_LocationChanged (Location1 As Location)
Dim latstr,lonstr As String

location2.Initialize2(LatOld, LonOld)

latstr = Location1.ConvertToMinutes(Location1.Latitude ).Replace(",",".").Replace(":","")
lonstr = Location1.ConvertToMinutes(Location1.Longitude).Replace(",",".").Replace(":","")
If latstr >= 0 Then
latstr = latstr & ",N,"
Else
latstr = latstr & ",S,"
End If
If lonstr >= 0 Then
lonstr = lonstr & ",E,"
Else
lonstr = lonstr & ",W,"
End If

SentencaNmea = "$GPRMC," & DateTime.Time(Location1.Time).Replace(":","") & ",A," & _
latstr.Replace("-","") & lonstr.Replace("-","") & Location1.Speed & "," & _
NumberFormat(Location1.Bearing,1,1) & "," & DateTime.Date(Location1.Time).Replace("/","") & ","
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Apparently this is the format returned from Location.ConvertToMinutes which is a native method.
You can use this Convert sub instead:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Log(convert(-22.02))
    Log(convert(22.99))
    Log(convert(0))
End Sub

Sub Convert(Value As Double) As String
    Dim sb As StringBuilder
    sb.Initialize
    If value < 0 Then
        sb.Append("-")
        value = -value
    End If
    sb.Append(Floor(value)).Append(":")
    sb.Append(NumberFormat((value - Floor(value)) * 60, 2, 3))
    Return sb.ToString
End Sub
 
Upvote 0
Top