You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another solution for this problem is to use a square instead -- this makes it a bit easier on the maths involved because you simply use a greater-than / less-than comparison on the lat/lng coordinates.
This should also set a placeholder for "results_msg" or "no_results" where we can say "There are X results within Y miles of you!" or "There were no results".
CREATE PROCEDURE geodist (IN userid int, IN dist int)BEGINdeclare mylon double; declare mylat double;declare lon1 float; declare lon2 float;declare lat1 float; declare lat2 float;
-- get the original lon and lat for the userid
select longitude, latitude into mylon, mylat from users5where id=userid limit 1;
-- calculate lon and lat for the rectangle:
set lon1 = mylon-dist/abs(cos(radians(mylat))*69);set lon2 = mylon+dist/abs(cos(radians(mylat))*69);set lat1 = mylat-(dist/69); set lat2 = mylat+(dist/69);
-- run the query:
SELECT destination.*,3956 * 2 * ASIN(SQRT( POWER(SIN((orig.lat -dest.lat) * pi()/180 / 2), 2) +COS(orig.lat * pi()/180) * COS(dest.lat * pi()/180) *POWER(SIN((orig.lon -dest.lon) * pi()/180 / 2), 2) )) asdistance FROM users destination, users originWHERE origin.id=userid
and destination.longitude between lon1 and lon2 and destination.latitude between lat1 and lat2
having distance < dist ORDER BY Distance limit 10;END $$
Really, this would need to be a variation on the resourceQuery Snippets.
The text was updated successfully, but these errors were encountered:
A variation on the Gmarker snippet:
Include a &radius parameter that will filter the viable resources specified by the other parameters (i.e. the &parents or &resources).
E.g.
OR
&radius=
5
&units=miles
Related: add a system setting specifying the unit (miles or kilometers).
Search for "Great Circle" calculations for some inspiration:
http://stackoverflow.com/questions/574691/mysql-great-circle-distance-haversine-formula
http://stackoverflow.com/questions/1727137/sql-query-for-performing-radius-search-based-on-latitude-longitude
Another solution for this problem is to use a square instead -- this makes it a bit easier on the maths involved because you simply use a greater-than / less-than comparison on the lat/lng coordinates.
This should also set a placeholder for "results_msg" or "no_results" where we can say "There are X results within Y miles of you!" or "There were no results".
A related search is "Find the closest to me" -- check out this braindump powerpoint!
http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
Also http://www.sphinxsearch.com/
Sample query:
Really, this would need to be a variation on the resourceQuery Snippets.
The text was updated successfully, but these errors were encountered: