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.
Here's a few ideas, some of which may not apply depending on your exact situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With