How to sum of arrays of floating point numbers

stuck

How to sum of arrays of floating point numbers..as the results from distance that the array float come from results Location.distanceBetween(latStart, longStart, latB, longB, results); method in Google maps api ,,i'm trying with this, but at some point it decrease, it should always incrementing. what am i missing?

EDIT:

public float total(ArrayList<LatLng> listPoints){
        if(listPoints.size()==2){
            listPoints.clear();
        }
        listPoints.add(latLng);
        float[] results = new float[2];
        float sum  = 0.0f;
        for (int z = 0; z < listPoints.size(); z++) {
            if(listPoints.size() == 1){
                latStart = listPoints.get(z).latitude;
                longStart = listPoints.get(z).longitude;
                Toast.makeText(this, "listPoint 1", Toast.LENGTH_SHORT).show();
            }else if(listPoints.size() == 2){
                latB = listPoints.get(z).latitude;
                longB = listPoints.get(z).longitude;
                Toast.makeText(this, "listPoint 2", Toast.LENGTH_SHORT).show();
            }
            Location.distanceBetween(latStart, longStart, latB, longB, results);
            sum+=results[0];
        }
        tvJarakTotal.setText(sum + "");
        return sum;
    }

EDIT: the distance came from onLocationChanged() method as the user location is moving,

EDIT: I Finally find the solution myself, by creating some trick using sharedPreference. but the accepted answer is correct to the question.

Tim Biegeleisen

It is not entirely clear what you think you were doing in your code above. First of all, the Location#distanceBetween API takes in a pair of latitude longitude values, i.e. two geographic points, and then returns the distance between them in results[0] (q.v. the documentation).

Next, it isn't clear what the starting and ending points are intended to be. I answered below under the assumption that the listPoints are one set of points (either starting or ending), and the vales latB and longB are a fixed set of starting/ending points. Without this assumption, an answer really can't be given here.

public float total(ArrayList<LatLng> listPoints) {
    float[] results;
    float sum = 0.0f;
    for (int z=0; z < listPoints.size(); z++) {
        double latStart = listPoints.get(z).latitude;
        double longStart = listPoints.get(z).longitude;
        Location.distanceBetween(latStart, longStart, latB, longB, results);
        sum += results[0];
        tvJarak.setText(sum + "");
    }

    return sum;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Sum of Floating Point numbers in Objects. ( Typescript )

how to input floating point numbers

How to calculate multiple floating point column sum

How to increment floating point numbers by 1?

How to convert dataframe dates into floating point numbers?

How to get the average of two floating point numbers

How to print floating point numbers from assembly?

How are floating point numbers stored inside the CPU?

Understanding how these floating point numbers work?

PROLOG - How to round decimals of floating point numbers?

How to capture numbers in specific range with floating point?

How to substract floating point numbers with high precision

recursive function for subset sum problem with floating-point numbers

Getting SUM of MySQL table data when there is floating point numbers

How to sum the numbers of two arrays

Floating point numbers in bash

Formatting Floating Point Numbers

Extreme Floating Point Numbers

Classifiers on floating point numbers

Set of floating point numbers

product of floating point numbers

Negative Floating Point Numbers

How to read a txt file containing floating-point numbers separated by spaces using streams to obtain the sum, average, maximum, and minimum?

How does Enumerable#sum avoid floating point rounding errors?

How to find shortest decimal number between two floating point numbers

How can I pass floating point numbers as template parameters?

Python - How to add zeros to floating point numbers between -1 and 1

How does casting from integers to floating-point numbers work?

How are upper and lower bounds for floating point numbers determined?