I have a program that loops over a list of vehicle co-ordinates and then performs other functions on them. I am only looking for pairs of successive co-ordinates that are not too close together. If a vehicle is stationary for a long time, there is the potential for thousands of successive co-ordinates to be on top of each other.
Once I find my two co-ordinates, I am manually updating my iterator (i=j-1) so that I don't have to go over the many thousands of co-ordinates repeatedly. My question is, is this good practice? Or is there a viable alternative? I could not find any examples of this online. I saw the 'continue' statement, however this seemed like it would require an extra if statement, and the manual update was more 'elegant'.
int LatLngSize = latLngList.size();
for (int i = 0; i < LatLngSize; i++) {
j = i + 1;
validPoints = true;
if (LatLngSize > j) {
latLng1.setCoordinate(latLngList.get(i));
latLng2.setCoordinate(latLngList.get(j));
consecutivePointDistance = latLng1.distance(latLng2);
}
while (consecutivePointDistance < 0.05) {
j++;
if (LatLngSize > j) {
latLng2.setCoordinate(latLngList.get(j));
consecutivePointDistance = latLng1.distance(latLng2);
i = j - 1; // This is the potential offender.
} else {
validPoints = false;
consecutivePointDistance = 100;
}
}
//Do stuff with my latlng1 and latlng2
}