Directional Map Search
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 ho开发者_如何学运维w 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!
Thank you vartec for your help, but I found this site http://www.movable-type.co.uk/scripts/latlong.html which gives loads of information to do with co-oridnates and calculations.
It is possible with database that has spatial extensions.
I think you're using MySQL, it's spatial extensions are described here: http://dev.mysql.com/doc/refman/5.5/en/spatial-extensions.html
精彩评论