Closed bre7 closed 10 years ago
What do you mean by server side?
Instead of "SELECT * FROM location", I'd like to known if it's possible to send the location and only receive the nearest store (and prevent the client from receiving the entire list).
If you pass the origin latitude and longitude over you can do the distance formula in the query but if you have lots of locations it's going to be pretty slow. If you don't have a lot be sure to index the latitude and longitude columns and you can do something like the following. Note the $origLat and $origLng variables and the "locations" table twice.
SELECT * FROM locations
JOIN(
SELECT (3956 * 2 * ASIN( LEAST(1, SQRT( ( POW(SIN((RADIANS(`lat`) - RADIANS($origLat)) / 2), 2) + COS(RADIANS($origLat)) * COS(RADIANS(`lat`)) * POW(SIN((RADIANS(`lng`) - RADIANS($origLng)) / 2), 2) ) ) ) ))
AS distance FROM locations
) AS location
WHERE `lat` BETWEEN $origLat - (50 / 69) AND $origLat + (50 / 69) AND `lng` BETWEEN $origLng - (50 / (69 * COS(RADIANS($origLat)))) AND $origLng + (50 / (69 * COS(RADIANS($origLng))))
ORDER BY distance
LIMIT 1
Thanks bjorn
Has anyone been able to do this ? Only show the nearest location or none, I want to avoid showing all of them. @bjorn2404 explained it on the blog: http://www.bjornblog.com/web/jquery-store-locator-plugin#comment-15972 but is there a way to do it server side ?
thanks..awesome plugin by the way