[TYPO3-mvc] How would you realize a radius search

Claus Due claus at wildside.dk
Tue Feb 19 10:33:32 CET 2013


Hi everybody,

> Unless you have proper spatial support in your database I would suggest
> to do it in a 2-pass algorithm, first filter records with a SQL query
> using a rectangular area (min/max latitude/longitude) and only then
> calculate the real distance to further trim-down the result set.

Ideally I agree 100% with this, assuming you require speed as well as precision.
However, there are ways to do this in MySQL only. It's called the haversine()
formula - the Vincenty formula is the best but also most complicated. Haversine
is less complex (and can actually be performed directly in raw SQL, but is slow)
but has an error margin of upwards of 20 km (on huge lattitudal distances) due
to seeing the earth as a perfect sphere.

If you're doing local search with a limited result set, it's definitely worth searching
a bit for a nice haversine() in MySQL syntax. Many exist, pick the fastest one - it's
an excellent starting point and a perfectly fine solution for local search with less
precision, which I would say a "show nearest shops" search fits perfectly ;)

Cheers,
Claus


More information about the TYPO3-project-typo3v4mvc mailing list