Different results with GPS Tripmaster

D

Deleted member 103

Guest
Hi,

I have a test with my Tripmaster made with different devices and compared with the odometer of my car.
My Tripmaster used on all 3 systems the same routine, so I expect approximately the same results.

Here the result:
  • Odometer of my car = 7120 meter
  • Samsung-S4 = 7100 meter
  • iPhone 5 = 7269 meter
  • Lumia 535(WP8.1) = 8194 meter
Samsung S4 is, as it looks, the best. :)
The Lumia 535 is a disaster. :mad:

I know the odometer is not calibrated, it can certainly not be so bad
 

Harris

Expert
Licensed User
Longtime User
GPS distance is accurate providing the method for accumulating it is accurate (fine). In many cases, it is finer than your automobile's odometer.
True, only of you use the right method of accumulating GPS distance. Sampling GPS (lat/lon) for distance accuracy needs to happen every second (or less).

The problem I have is that when indoors, lat / lon will wander... I need to use the Accuracy of GPS to determine if I should sum the distance (between last lat / lon AND this lat / lon) in the equation. Often, the accuracy will state less than 20 meters (good), so my code accumulates distance traveled when in fact I am standing still (bad).

This is a red herring that affects your odometer calculations.
 
D

Deleted member 103

Guest
Hi Harris,

Thanks for the reply.

I use in all three systems (Android, iOS, WP) almost the same code.

B4X:
Sub GPS1_LocationChanged(Location1 As Location)
    Dim locDistance As Float
       
    If Location1.Accuracy > 0 And Location1.Accuracy <= 20 Then
        If Location1.SpeedValid Then
            If GPSPathPreviuous.Speed > 0 Then
                locDistance = Location1.DistanceTo(GPSPathPreviuous)

                Distance = Distance + locDistance

            End If
   
            GPSPathPreviuous = Location1
        End If   
    End If
End Sub

Are you a better idea?
 

Cableguy

Expert
Licensed User
Longtime User
Hi guys,

First of all, I've never used GPS in code, so my thoughts on the subject may be off!
When doing trip sums, my logic would be to check the distance difference between actual and previous positions, and only add to the trip if the diference was bigger than current accuracy.

If you are checking GPS data every second and adding it to the trip, then you may end up with a much greater value than the real one.
imagine this:
you are a fixed point, you don't ever move, but you log your GPS position every second
If you start with an accuracy of 50m, and then it decreases to say 10m, you may be logged a trip of around 30 to 40 meters, even without moving!
 

Harris

Expert
Licensed User
Longtime User
Process_Globals:

Dim DEGREES_TO_RADIANS As Double : DEGREES_TO_RADIANS = (cPI / 180.0)
Dim EARTH_RADIUS As Double
' EARTH_RADIUS = 3959 ' miles
EARTH_RADIUS = 6371 ' km ' used as default - convert where required for NON SI reporting (ie. USA)


B4X:
Sub GetDistance(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double
' lat1 and long1 are the previous position, lat2 and long2 are the current position
    Dim rlat1, rlong1, rlat2, rlong2, p1, p2, p3, ret As Double
    rlat1 = DEGREES_TO_RADIANS * lat1
    rlong1 = DEGREES_TO_RADIANS * long1
    rlat2 = DEGREES_TO_RADIANS * lat2
    rlong2 = DEGREES_TO_RADIANS * long2
    p1 = Cos(rlat1) * Cos(rlong1) * Cos(rlat2) * Cos(rlong2) ' funcky code to measure distance - works very well so far
    p2 = Cos(rlat1) * Sin(rlong1) * Cos(rlat2) * Sin(rlong2) ' dont ask me how it works - but it does!!!
    p3 = Sin(rlat1) * Sin(rlat2)
    ret = p1 + p2 + p3
    If ret >= 1 Then ' greater than or equal to - otherwise NAN (not a number ) error
        Return 0
    Else
        ret = ACos(ret)
        ret = (ret * EARTH_RADIUS)
        'ToastMessageShow(" PVals: "&p1&" - "&p2&" - "&p3&CRLF&" Ret1: "&ret1&" Ret2: "&ret2&" Retp: "&retp&" Res: "&ret ,True)
        Return ret
    End If
End Sub

Like you did, I also check to see if speed is valid AND if greater than (ie. 2 kph) since you may get a speed indication when in or near buildings.

If gLoc.fAccuracy < 20 Then
If (gLoc.fSpeed * M_K) > SpdMoreThan Then ' when speed is valid and more than specified value (SpdMoreThan) - accumulate distance
dist = GetDistance(latstart, lonstart, latstop, lonstop)
....
 
D

Deleted member 103

Guest
Hi Harris,

why should be more precise and better than the standard function "Location1.DistanceTo (GPSPathPreviuous)" your function "GetDistance"?

I'm sorry but I can not understand it.:(

I think the standard function "Location1.DistanceTo (GPSPathPreviuous)" returns the correct result, or not?
 

Harris

Expert
Licensed User
Longtime User
I don't know what method (math) is used in Distanceto to be able to comment if it is accurate (android docs states it is approximate - below).
"Returns the approximate distance in meters between this location and the given location. Distance is defined using the WGS84 ellipsoid."

The code I provided I found years ago (prior to fused location provider) and it has served me well - very accurate.

Run tests and try it out...

Thanks
 
D

Deleted member 103

Guest
I think the biggest problem is that is also calculated a distance even if one does not move.

With "if Location1.SpeedValid" and "if GPSPathPreviuous.Speed" I have tried to correct the problem, unfortunately it does not work with all devices.
 
D

Deleted member 103

Guest
Then I should change the function as a @Cableguy proposed.
B4X:
Sub GPS1_LocationChanged(Location1 As Location)
    Dim locDistance As Float
      
    If Location1.Accuracy > 0 And Location1.Accuracy < 20 Then
        If GPSPathPreviuous.IsInitialized Then
            locDistance = Location1.DistanceTo(GPSPathPreviuous)

            If locDistance > GPSPathPreviuous.Accuracy Then
                Distance = Distance + locDistance
       
                GPSPathPreviuous = Location1
            End If

        End If
       
        If Not(GPSPathPreviuous.IsInitialized) Then GPSPathPreviuous = Location1
    End If
End Sub
 

Harris

Expert
Licensed User
Longtime User
I think the biggest problem is that is also calculated a distance even if one does not move.

With "if Location1.SpeedValid" and "if GPSPathPreviuous.Speed" I have tried to correct the problem, unfortunately it does not work with all devices.
Yes, that is true. A friend suggested to use the accellorometer to determine if the device was moving before summing distance. I couldn't figure out how...
Because of multi-path distortion, it may appear to the GPS system that it is motion (lat / lon changing) when in-fact it is stationary.

I use distance summing in vehicles, so I set the speed to be greater than 5 kph before adding. Even then, I will occasionally see the speed bouncing to 15, 20... when inside a building - thus summing distance incorrectly.

My product must use an ECM device (connected to the computer on Commercial Motor Vehicles), so I get the vehicle distance from it and only use GPS as a backup source and for location resolving.

It's a tough nut to crack. If you do come up with a valid solution, pls advise.

Thanks
 
D

Deleted member 103

Guest
Hi,

Here the new result with the new function proposed by @Cableguy:

  • Odometer of my car = 10800 meter
  • Samsung-S4 = 10798 meter
  • iPhone 5 = 10805 meter
  • Lumia 535(WP8.1) = 10793 meter

Not bad, right? ;)
 

Cableguy

Expert
Licensed User
Longtime User
Wait! Stop the Presses!!!!
You mean... I was not wrong in my thoughts???? LoL

Yes, much better indeed
 
D

Deleted member 103

Guest
I have to thank you, your idea was really helpful. :)

GRAZIE!!
 
Top