Directional Map Search
Posted
by Rooneyl
on Stack Overflow
See other posts from Stack Overflow
or by Rooneyl
Published on 2010-06-02T08:22:28Z
Indexed on
2010/06/02
8:23 UTC
Read the original article
Hit count: 322
Hello, I am trying so write a bit of code that will search for a given point on a map, but in a given arc of a compass bearing.
e.g. 45 degress (north-east), 20 degrees either side.
So far I have got a SQL command that will give me the results in a given radius, need some help on how to filter it to a direction.
SELECT * FROM (SELECT `place1_id`, `place2_id`, ( 6371 * acos( cos( radians(search_latitude) ) * cos( radians( `location_lat` ) ) * cos( radians( `location_long` ) - radians(search_longitude) ) + sin( radians(search_latitude) ) * sin( radians( `location_lat` ) ) ) ) AS `distance` FROM `place` ORDER BY distance) AS `places` WHERE `places`.`distance` < search_radius AND `places`.`place2_id` = ?
Will I be able to do this (if possible) all in SQL, or will it need a bit of PHP applying to it?
Any and all help much appreciated!
© Stack Overflow or respective owner