To search nearest locations to given locations, order by distance
- Should I use float or Point?
- Should I pre-compute value of cos/sin/sqrt http://www.movable-type.co.uk/scripts/latlong-db.html
- My searches are various locations within one city.
- Many OLD posts are telling mysql is not having proper geo support, Is it true with latest MySQL version as well?
We are using
double
to storelatitude
andlongitude
. In addition we precomute (by triggers) all values which are precomputable when looking at one point only. I currently don't have access to the formula we are using, will add this later. This is optimized for an optimal speed / precision balance.For defined area searches (give me all points within x km) we additionally store the lat/lng value multiplied with
1e6
(1,000,000) so we can limit into a square by comparing integer ranges which is lightning fast e.g.EDIT:
Here's the formular and precalculation of values of the current place in PHP.
WindowSize is a value you have to play with, it's degrees factor 1e6, used to narrow down the possible results in a square around the center, speeds up result finding - dont forget this should be at least your search radius size.
Searching all rows within a specific range of my center
The formular has a quite good accuracy (below a metre, depending where you are and what distance is between the point)
I've precalculated the following values in my database table
example
Example trigger
Questions? Otherwise have fun :)