Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store distance between cities and towns in DB efficiently

I need to be able to display distance to n cities/towns from a particular location chosen by user. Its like clicking on a map and getting all destinations within 100 miles, only that it wont be a map but a link on webpage.

I need to choose a solution that would scale-up from within a state to a country to globally potentially - which means from thousand to hundred thousand locations.

I though of storing CITY1_ID, CITY2_ID & DISTANCE in a Relational DB table, but I doubt if it would scale well for a web application (million of rows).

Could this be done more efficiently using a NoSQL Database or Graph DB ? Or is RDBMS good enough for this problem with proper design?

Added: If I do not store in DB then how will I get something like: Get me all cities within 100 miles of San Jose?

like image 733
AJ. Avatar asked Oct 02 '12 20:10

AJ.


People also ask

How does MySQL calculate distance?

Calculating Distance in MySQL To get the distance between two points, you call the function with the two points as the arguments: -- Returns distance in meters.


1 Answers

you should store city_id, latitude, longitude one for each city - then calculate the distances based on runtime input.

like image 183
Randy Avatar answered Nov 14 '22 21:11

Randy