Reputation: 1231
I am making a website where users can create routes on google maps and I have been looking around for the best way to store a path (the coordinates of there root) from google maps. I have found a few different options and I am not sure which is the best.
Should I
Store them in a JSON file then just store the path of the json file in a sql column? The only problem with that is I then cant make querys based off the coordinates in the json file.
or
Store every single latitude and Longitude point in a separate row? The only problem I see with this is one path on google maps could have over 1000 different points which would take up a lot of space in the database.
Any other ideas?
Upvotes: 3
Views: 1741
Reputation: 204756
Store the points seperate in a table like this
coordinates table
-----------------
track_id
lng
lat
sequence_number --> you should also store a sequence to know the order in which you want to connect the coordinates
and another table containing the track info
tracks table
------------
id
name
other_stuff
If you then want to get all points of a track called My Bicycle Tour
then run
select c.lng, c.lat, c.sequence
from coordinates c
join tracks t on t.id = c.track_id
where t.name = 'My Bicycle Tour'
order by c.sequence
Remember a DB can easily hold millions and even billions of records and with proper indexes this is also very fast to query.
Upvotes: 3