I am trying to update distance traveled between GPS coordinates. My error is that the GPS can move short distances while sitting still. I am currently simply adding the new coordinates to a list every second, calculating the distance between this second and last second, then appending the distances to a new list then add them all together.

The issue is that the small movements in distance keep accumulating. Does anyone know the proper way to do this?

self.breadcrumbs = []

#Calc Linear Distance GPS
while 1:
    report = gpsp.get_current_value() #Retrieves GPS Values
        self.lat = report.lat
        self.lon = report.lon
        self.latlon = (self.lat, self.lon) #Put lat lon into tuple 
        self.breadcrumbs.append(self.latlon) #Append lat lon to breadcrumb list
        breadcrumb_distances = [] #Holds distances between latlon data points
        for i, b in enumerate(self.breadcrumbs):
            current_location = b
            last_location = self.breadcrumbs[i - 1]
            miles = geodesic(current_location, last_location).miles 
            feet = miles * 5280 #convert to feet
        cumulative_distance = round(sum(breadcrumb_distances),2)
    except Exception as e:
  • 1
    this is not a RPi question
    – jsotola
    Commented Jul 21, 2020 at 17:50
  • 2
    @jsotola You’re right. I should go over to Stack and ask this one.
    – Mike C.
    Commented Jul 21, 2020 at 18:10
  • 1
    You're shooting yourself in the foot. Why do you add distance when the velocity is zero/near zero? You could start here
    – Seamus
    Commented Jul 21, 2020 at 21:43
  • 1
    @Seamus Thanks for the tip. I’ll check it out.
    – Mike C.
    Commented Jul 21, 2020 at 21:52
  • 1
    Hope it helps... you will almost always get a better outcome in these Q&A forums if you do a bit of homework beforehand.
    – Seamus
    Commented Jul 21, 2020 at 21:59

1 Answer 1


I would advise that you lookup the use of Kalman filters or similar to handle such, but the maths can be heavy so you have been warned. You may also need a second sensor, an accelerometer, which will give you two measures of velocity tat you can then fuse into a single more accurate measure.

Not the answer you're looking for? Browse other questions tagged or ask your own question.