Answer the question
In order to leave comments, you need to log in
How to properly organize work with a database that stores coordinates in large quantities?
Given: MySql, about 1 million records. The main fields are Latitude and Longitude, which store the coordinates respectively.
It is necessary to display a list of coordinates located at a certain distance from a given coordinate. I do it in a simple way, I calculate the distance from the initial point and get the coordinates of the square with the known points in the upper left corner of the square and in the lower right corner of the square, and I select the database with the query: SELECT * FROM $table WHERE lat > '$posLat1' AND lat < '$posLat2' AND lon > '$posLon1' AND lon < '$posLon2'
That is, a continuous comparison of the given coordinates with the continuous search available in the table is carried out. And with so many entries, this business takes up to 4 seconds. I tried to make an index on the lat field, but the result is the same.
Yes, and I can not understand how the index of the field containing the Double type will be produced. Maybe you need to create an additional field for lat in which to write an integer with cutting off decimals, etc., index this field and pre-select it? In general, if anyone has any thoughts on this, please tell me.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question