Error calculating cumulative distance traveled in android

0

I do the calculation in a thread

    Thread thread = new Thread() {
    @Override
    public void run() {
        try {
            while(true) {
                sleep(1000);
                Coordenada coordenada  =getLocation();

                Location locationA = new Location("point A");

                locationA.setLatitude(lat);
                locationA.setLongitude(longi);
                Location locationB = new Location("point B");

                locationB.setLatitude(coordenada.getLat());
                locationB.setLongitude(coordenada.getLongg());

                distancia = distancia + (locationA.distanceTo(locationB));
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
};

getLocation () is a method that returns latitude and longitude, that works correctly, the thread I throw with a button and I stop it with another one but the result obtained in distance is 0.0.

What can be the error?

    
asked by Matias Blanco 15.03.2018 в 01:17
source

0 answers