GPS Speed reported as Integer not a Float

brainfart

Member
Licensed User
Longtime User
Hello.
I am not claiming that it is a bug yet, because I only checked it on one device (AT&T-Samsung Infuse)
When retrieving the Speed from GPS_LocationChanged event it is reporting integer value instead of Float.
Documentation says it is reported as Float and UOM is m/s so to get km/h you need to multiply it by 3.6 and to get mph you need to multiply it by 2.2369.
I have noticed that speed was reported with big increments so I passed the speed variable directly to a label without any math and took it for a ride.
The label reported no decimal places just integer values in m/s
Without the fractions of m/s in the speed parameter, the resulting precision will be poor, (like 3.6km/h resolution) and not acceptable. Could someone check this to see if there is a library error or is it just my device I am testing on.

Here is an experimental version of my code:

B4X:
Sub GPS_LocationChanged (Location1 As Location)
    Dim spd As Float
    Log("Location event")
    If Location1.SpeedValid = True Then
        If MPH = True Then
            '1mph = 1.609344kph
            spd = Location1.Speed * 2.2369
            Label1.Text = Location1.Speed & "m/s"
            Label2.Text = spd & "mph"
        Else
            spd = Location1.Speed * 3.6
            Label1.Text = Location1.Speed & "m/s"
            Label2.Text = spd & "km/h"
        End If
    Else
        Label1.Text = "---"
    End If
End Sub

Thank you.
 

agraham

Expert
Licensed User
Longtime User
The Location object from the GPS library definitely passes a Float as the Speed property and it obtains this directly from the Android Location object so I guess what you are seeing is what is really being provided. I don't know if this is a general Android limitation or is a feature of your particular device.
 

awama

Active Member
Licensed User
Longtime User
Hello brainfart,

I have a ZTE-Blade and a Samsung Galaxy S2.
I tested Location1.Speed on my 2 devices.
When ZTE-Blade provide a value for example 4,25 then SGS2 has a value 4. ZTE-Blade show 4,75 then SGS2 show 4. ZTE-Blade show 5,25 then SGS2 has a value of 5. SGS2 shows only Integer values. ZTE-Blade shows also float values

Walter
 

rbsoft

Active Member
Licensed User
Longtime User
Sorry - I just was about writing some nonsense.
 
Last edited:

brainfart

Member
Licensed User
Longtime User
Thanks awama.
Looks like Samsung issue.
I have checked the speed reported by Google Navigation and it also report speed by increments of about 2.24MPH indicating it is also getting integers from the GPS sensor driver.
I created another test app that logged the Location1.Speed and found it interesting.
All the speeds are integers except 5,9,15,19,25,29.....m/s
These are the only ones that have a decimal and it is (don't have the info in front of me) something like 15.000000021 then back to 16, 17 etc.

I will search on other forums to see if this is a known, wide spread issue with Samsung. I would not be surprised.
 
Top