I have a table with a structure like this:
table name: shop
id_shop int(10)
name varchar(200)
latitude double
longitude double
And I would like to calculate the distance between the given coordinates and the coordinates stored in the database.
My current request:
SELECT *
FROM `shop` AS `s`
WHERE
(
( 6371
* ACOS(
SIN( RADIANS( latitude ) )
* SIN( RADIANS( 53.5353010379 ) )
+ COS( RADIANS( latitude ) )
* COS( RADIANS( 53.5353010379 ) )
* COS( RADIANS( 14.7984442616 ) - RADIANS( longitude ) )
)
)
<= 25
)
plus some JOIN LEFTfor some data.
Is there any way to optimize this query? With joins, it takes about 13 ms.
I need to add here some LIMIT, and COUNT(*)for the total number of stores for pagination.
source
share