本文介绍了在 Doctrine 中使用 Haversine 进行 SQL 搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我想通过坐标进行搜索,即我想要一个像这样工作的函数:
I want to do a search by coordinates, i.e. I want to have a function that works like this:
function getLocationsInCircle($lat, $long, $minDist, $maxDist){
//return all the places that are at least $minDist
//kilometers away and no more than $maxDist kilometers away
}
我有一个位置"表,用于存储所有位置 ID 及其纬度和经度.
I have a "location" table that stores all location Ids and their latitude and longitude.
harsine 公式足以满足我想要做的事情
The haversine formula is good enough for what I want to do
6371 * ACOS(SIN(RADIANS( $lat )) * SIN(RADIANS( latitude )) + COS(RADIANS( $lat )) * COS(RADIANS( latitude )) * COS(RADIANS( longitude ) - RADIANS( $long )))
我只是不知道如何在 Doctrine 中运行该查询.
I just don't see how to run that query in Doctrine.
推荐答案
试试这个:
Doctrine_query::create()->select('id')
->addSelect("(6371 * ACOS(SIN(RADIANS($latitude)) * SIN(RADIANS(l.latitude)) + COS(RADIANS($latitude)) * COS(RADIANS(l.latitude)) * COS(RADIANS(l.longitude) - RADIANS($longitude)))) as Distance")
->from('Location l')
->having("Distance > $minDist AND Distance < $maxDist");
这篇关于在 Doctrine 中使用 Haversine 进行 SQL 搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)