I was wondering how I could get the nearest location from given float values.
I have an ArrayList of Cities which have lat/long. What I would like to do is to find the nearest city from given coordinates.
public class City {
private float lat;
private float lng;
//getters & setters
}
List < City > cities; // at this point "cities" contains several "city"
City city;
city = findNearest(lat, lng);
private City findNearest(float lat, float lng) {
for (City c: cities) {}
}