2

I have a table (DB2 database) with city information and corresponding latitude and longitude and many other info related to the city. My requirement is:

Input to my application will be latitude and longitude which may or many not be exact lat and long stored in DB. I need to find the nearest City info from the table with the help of input latitude and longitude. Any help is highly appreciated.

Is there a nearest neighbor implementation in java available for this or SQL to handle this

Sinan
  • 11,443
  • 7
  • 37
  • 48
Ram
  • 21
  • 1
  • 2

1 Answers1

2

You could use a KD-Tree:

KDTree Implementation in Java

Within SQL, you could Pythagoras to find, and then order by, the distance from a given point, but this likely wouldn't be very efficient.

Community
  • 1
  • 1
Stoive
  • 11,232
  • 4
  • 24
  • 32