Arduino GPS travelled distance problem

i made a project which calculates travelled distance. but there is a problem. because of gps error , device thinks that you re moving . although i am standing exact same location, my device think that i am moving and "travelled distance" increases. what is the ways of avoid this?
1- i think that i made rare calculation it decrease. so i made each measurement in every 10 seconds. it works but not enough
2- maybe i can put my code speed condition. so bellow 2 km/h not accumulates.

what is ur recommendation to solve this problem? any approach is acceptable for me and you can make comment about my code. i am a little noob:D
thank you

mycode:

#include <SoftwareSerial.h>

#include <TinyGPS.h>


TinyGPS gps;
SoftwareSerial ss(3, 4);

//distance
float slat=39;
float slon=27;
unsigned long age=0;
unsigned long sum_distance1=0;
unsigned long sum_distance2=0;
int distance=0;

//timer
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;

//sensor
#define sensorpin A0
int sensor;

#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);



void setup()
{
  Serial.begin(115200);
  
  ss.begin(9600);

  pinMode(sensorpin,INPUT);

  //opening screen
  u8g.firstPage();
    do {
      u8g.setFont(u8g_font_profont12);
      u8g.setPrintPos(0, 10);
      u8g.print("Mesafe Olcer");         
      u8g.setPrintPos(0, 25);
      u8g.print("GPS'ye baglaniyor");      
      u8g.setPrintPos(0, 40);        
      

    } while (u8g.nextPage() );
    delay(1000);
  

  while(1){
    smartdelay(1000);
    gps.f_get_position(&slat, &slon, &age);  
    Serial.print("slat: "); Serial.println(slat,6);
    Serial.print("slon: "); Serial.println(slon,6);   
    if(slat>1 && slat<100) break;

    
    u8g.firstPage();
    do {
      u8g.setFont(u8g_font_profont12);
      u8g.print("=");
      } while (u8g.nextPage() );
    delay(10);

    
  }
  
}

void loop()
{
  Serial.println("--------------------");
  smartdelay(1000);

  uint8_t sat =gps.satellites();
  Serial.print("sat: "); Serial.println(sat);

  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  Serial.print("flat: "); Serial.println(flat,6);
  Serial.print("flon: "); Serial.println(flon,6);
  Serial.print("slat: "); Serial.println(slat,6);
  Serial.print("slon: "); Serial.println(slon,6);

  float spd=gps.f_speed_kmph();
  Serial.print("spd "); Serial.println(spd);

  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age2;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age2);
  hour+=3;if(hour>=24)hour-=24;

  // sensor
  sensor=analogRead(sensorpin);
  Serial.print("sensor: "); Serial.println(sensor);


 
  //distance measurement
  currentMillis=millis();
  if(currentMillis - previousMillis >= 10000){
    distance = TinyGPS::distance_between(flat, flon, slat, slon);
    if (distance>250 || distance<0 ) distance=0; //set distance 0 if measure larger
    
    else{
      slat=flat;
      slon=flon;
      sum_distance1=sum_distance1+distance;
      if (sensor>350 ) sum_distance2=sum_distance2+distance;
      Serial.print("sum_distance: "); Serial.println(sum_distance1);
      Serial.print("sum_distance2: "); Serial.println(sum_distance2);
    }
    
      Serial.print("distance "); Serial.println(distance);
    


    previousMillis=currentMillis;
  }



//print oled  
   u8g.firstPage();
    do {
      u8g.setFont(u8g_font_profont12);
      u8g.setPrintPos(0, 10);
      u8g.print(sat);
      u8g.setPrintPos(64, 10);
      u8g.print(distance);
      
      
      u8g.setPrintPos(0, 25);
      u8g.print(hour);
      u8g.setPrintPos(10, 25);
      u8g.print(":");
      u8g.setPrintPos(20, 25);
      u8g.print(minute);

      if (sensor>350){
        u8g.setPrintPos(64, 25);
        u8g.print("++++");
      }
      
      u8g.setPrintPos(0, 40);
      u8g.print("top: "); u8g.print(sum_distance1);
      u8g.setPrintPos(64, 40);
      u8g.print("sen: "); u8g.print(sum_distance2);
      
      u8g.setPrintPos(0, 55);
      u8g.print("hiz: ");
      u8g.print(spd);
    } while (u8g.nextPage() );
    delay(10);
  
//  u8g.firstPage();
//  do {
//    draw2();
//  } while (u8g.nextPage());
//  delay(3500);


  
}

static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

Your topic was MOVED to its current forum category as it is more suitable than the original

Only add to the distance moved if a significant change of location is reported

I use tinyGPS++. It provides a flag .updated,that can be checked. My device is a NEO-6M. Sometimes 1 or 2 km/h appears.
How many satellites does it find?

The function smartdelay looks strange to me. In my opinion checking for data available, and reading the data should be done as often as possible, without any delays, without any restrictions,

it is a good way. maybe 10 meter. right?

generally it founds 6 sattalite. i m using neo7m.
now it s 1 hour that i start my gps and it calculates 1800 meters:D

i think same. but i don't know how to handle it. could you be more specidic?

Try it but I'm afraid it will not be enough. 10 meters is a usual uncertainty.
Building a GPS based device one helper showed a plot of the position during ?? time. There were dots spread out on an area like 1000 square meters.

Do the polling first in loop. If any data is updated, do the work You want to be done. I'm fiddling with a tine mobile so cut and paste etc is difficult.
Later today I'll have the Pc at hand.

It depends on what you consider to be a significant distance. How much does the position change if the GPS unit is not moving ?

You could, of course, take several position readings over a period and average them