I am trying to order a list of points by distance from a given point.
The application is to find the nearest landmarks (gps coordinates) to your current gps coordinate.
so if you take the following code :
public static void main(String[] args) throws SQLException {
ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>();
Point2D.Double point1 = new Point2D.Double(1,1);
Point2D.Double point2 = new Point2D.Double(2,2);
Point2D.Double point3 = new Point2D.Double(3,3);
points.add(point1);
points.add(point2);
points.add(point3);
Point2D.Double myPoint = new Point2D.Double(4,4);
}
If i use a Comparator to sort the points array I will get a nice ordered list of points but how do I find which one is closer to myPoint? and what are the distances.
That should certainly answer my question, but for bonus points.. how can I limit the result of points back if give a maximum distance. eg : return an ordered list of coordinates that are no further than 100 miles.