-1

I'm developing an Android app that tracks the users location. I have it running locally so my LatLng are getting stored in an array :

ArrayList<LatLng> points = new ArrayList<>();

In onLocationChanged it then uses this to draw a poly line, this all works perfect for me. I want to calculate the distance of the entire journey. Is there a way to do this using my array?

ColdFire
  • 6,764
  • 6
  • 35
  • 51
JamesD
  • 98
  • 7
  • You simply have to sum all the distances between two consecutive points in the list? But it smells like a homework :) – stan0 Apr 07 '18 at 08:35

2 Answers2

0

You could make a loop that go through your array and compute the distance between two consecutive points. Then add every distance computed to obtain the whole trip distance. This should look like this (in pseudo code) :

totalDistance;
for(points in listOfPoints){
    nextPoint = listOfPoints.indexof(point + 1);
    distance = computeDistance(point, nextPoint);
    totalDistance.add(distance);
}
vincrichaud
  • 2,218
  • 17
  • 34
0

For calculation distance between location points, you need at least two points.

Calculation can be found here: https://stackoverflow.com/a/365853/1537916

mmmatey
  • 666
  • 8
  • 15