0

As from this page, distanceBetween() returns inaccurate result? I'm trying to calculate the distance from a user location everytime the user ismoving. How to make this for loop, if there is new results, add it to old result, then setText() it. I'm trying with ++ like this: tvJarak.setText(results[0]++ + ""); but did not work.

for (int z = 0; z < listPoints.size(); z++) {
    float[] results = new float[1];
    Location.distanceBetween(latStart, longStart, latB, longB, results);
    tvJarak.setText(results[0] + "");
}

i edit :

float[] results = new float[1000];
        for (int z = 0; z < listPoints.size(); z++) {
            Location.distanceBetween(latStart, longStart, latB, longB, results);
            results[0]+=results[1];
        }
        tvJarak.setText(results[0] + "");

it gives weird number randomly. it should be ++

stuck
  • 57
  • 8

1 Answers1

3

Your Problem is, that results[0]++ adds one after setText() was executed.

Use ++result[0] instead. It will first add one and then execute setText().

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Gurkonier
  • 116
  • 3