I'm adding in a loop, but the return value is always 0, I can't figure it out.
If I uncomment one of the final 2 lines, it returns the manual value correctly, and the rest of the class works. ARRAYLIST_SIZE = 10.
public float averageBearing() {
float sumBng = 0;
for (int i = 0; i==ARRAYLIST_SIZE; i++) {
Location l = locList.get(i);
float tempBearing = l.getBearing();
sumBng += tempBearing;
}
float finalBng = sumBng/ARRAYLIST_SIZE;
//remove following lines for real use
//finalBng = (float) (Math.random()*360);
//finalBng = (float) 105.0;
return finalBng;
}
I am reasonably sure the locations in the list have bearings, here is the add method. I have to spoof the bearing for now because the location only has it if we're moving, but I'm at my stationary desk.
public void add(Location location) {
if (locList == null) {
locList = new ArrayList<Location>();
}
//test code to spoof bearing
location.setBearing((float) 105.0);
//use only locations with extra data
if (location.hasBearing() && location.hasSpeed()) {
locList.add(location);
mostRecent = location;
//ensure we have at most 10 recent locations
//no reason to use stale data
while (locList.size()>10) {
locList.remove(0);
}
}
ARRAYLIST_SIZE = locList.size();
}