Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the nearest places from a Latitude/Longitude in MySQL table?
    primarykey
    data
    text
    <p>I want to make a table of with columns in a MySQL database:</p> <ol> <li>Index</li> <li>Latitude</li> <li>Longitude</li> <li>Places like place of Countries, Cities, People, Building etc.</li> </ol> <p>With huge number of rows, in order of hundred thousands until million of rows.</p> <p><strong>If I want to get nearest places of a selected row in the table, how can I do that in the fastest way?</strong></p> <p>It is no problem if more information, indexing, or presorting are necessary.</p> <p>======<br /> Edit 1:<br /> I have read the answer and the answer is using a formula, for example from the best answer:<br /> (((acos(sin((".$latitude."*pi()/180)) * sin((<code>geo_latitude</code>*pi()/180))+cos((".latitude."*pi()/180)) * cos((<code>geo_latitude</code>*pi()/180)) * cos(((".$longitude."- <code>geo_longitude</code>)*pi()/180))))*180/pi())*60*1.1515*1.609344)<br /></p> <p>If I have 1 million rows, that means, there are 1 million of expensive calculation. I thing it will be very slow.<br /><br /></p> <p>Are the optimization, for example using filtering in the beginning:<br /> 1. If the input is City A in location 10.000, 20.000, then filter cities that located at 9.000 to 11.00.<br /> 2. Calculate with the formula above.<br /></p> <p><strong>How to optimize the speed of that algorithm?</strong><br /></p> <p>====<br /> Edit 2:<br /> Sorry, I've only read the best answer.<br /> I found what I've looked for in the other answer: <a href="http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL" rel="nofollow">http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL</a><br /></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload