I'm doing kinda running tracking app. My app already tracks my path and distance, but I can't understand what do those numbers in distance mean. Here are the screenshots(1,2,3). I want to get my distance in kilometers in this format DISTANCE FORMAT, like on the picture(example: 1,11 KM). Please, help me. I'm new in Android Development, so could you please explain me how to do it.
Thanks beforehand.
HERE IS MY CODE
@Override
public void onLocationChanged(Location location) {
if (location != null) {
if(currentLocationMarker != null){
currentLocationMarker.remove();
}
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions marker = new MarkerOptions();
marker.position(latLng);
currentLocationMarker=mMap.addMarker(marker);
polylineOptions = new PolylineOptions();
polylineOptions.color(Color.RED);
polylineOptions.width(5);
arrayPoints.add(latLng);
polylineOptions.addAll(arrayPoints);
mMap.addPolyline(polylineOptions);
calculateMiles();
}
}
protected float calculateMiles() {
float totalDistance = 0;
for(int i = 1; i < polylineOptions.getPoints().size(); i++) {
Location currLocation = new Location("this");
currLocation.setLatitude(polylineOptions.getPoints().get(i).latitude);
currLocation.setLongitude(polylineOptions.getPoints().get(i).longitude);
Location lastLocation = new Location("this");
currLocation.setLatitude(polylineOptions.getPoints().get(i-1).latitude);
currLocation.setLongitude(polylineOptions.getPoints().get(i-1).longitude);
totalDistance += lastLocation.distanceTo(currLocation);
}
textAutoUpdateLocation.setText("Distance = " + totalDistance);
return totalDistance;
}