SQL search using Haversine in Doctrine(在 Doctrine 中使用 Haversine 进行 SQL 搜索)
本文介绍了在 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 搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:在 Doctrine 中使用 Haversine 进行 SQL 搜索
基础教程推荐
猜你喜欢
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
