I am working on a GUI application. The GUI consists of a map with cities. Each city has an X and a Y coordinate. The cities are stored in a HashMap like the following:
cities.put(new Coordinates(X, Y), "City Name");
Where X and Y are just some integers that represent the middle point of the city. As in if you had to label a city with a circle, the X and Y would represent the center of that circle.
I have no trouble getting the coordinates of the mouse click. However my problem is I do not know how to search through the HashMap and get the closest city. No person is going to be able to perfectly click on the specific X and the specific Y coordinate. So I have to allow like a +- 15.