定向地图搜索
我正在尝试编写一些代码来搜索地图上的给定点,但在罗盘方位的给定弧中。
例如,45 度(东北),两侧 20 度。
到目前为止,我已经得到了一个 SQL 命令,它将给出给定半径内的结果,需要一些关于如何将其过滤到某个方向的帮助。
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` = ?
我是否能够(如果可能的话)全部使用 SQL 来完成此操作,还是需要应用一些 PHP 来实现?
非常感谢任何和所有帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 vartec 的帮助,但我找到了这个网站 http://www. moving-type.co.uk/scripts/latlong.html,它提供了大量与坐标和计算有关的信息。
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.
具有空间扩展的数据库是可能的。
我认为你正在使用 MySQL,它的空间扩展如下所述:
http://dev.mysql.com/doc/refman/ 5.5/en/spatial-extensions.html
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