Hello !
I have a table with structure like that:
table name: shop
id_shop int(10)
name varchar(200)
latitude double
longitude double
And I'd like to calculate distance between given coordinates and coordinates saved in database.
My current query:
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 LEFT
's for some data.
Is there any way to optimize that query ? With joins it takes about 13msec.
I need to add here also some LIMIT
and COUNT(*)
for total amount of shops for pagination.