Postgresql CakePHP在WHERE子句中的函数名周围加引号
我正在使用PostgreSQL中earthdistance模块中的各种函数,其中一个是Postgresql CakePHP在WHERE子句中的函数名周围加引号,postgresql,cakephp,geolocation,Postgresql,Cakephp,Geolocation,我正在使用PostgreSQL中earthdistance模块中的各种函数,其中一个是ll_to_earth。给定纬度/经度组合,我试图通过CakePHP1.2.5从数据库中检索最近的点 // set dummy data $latitude = 30.4393696; $longitude = -97.6200043; // create a simple bounding box in the WHERE conditions, sort the points by location,
ll_to_earth
。给定纬度/经度组合,我试图通过CakePHP1.2.5从数据库中检索最近的点
// set dummy data
$latitude = 30.4393696;
$longitude = -97.6200043;
// create a simple bounding box in the WHERE conditions, sort the points by location, and retrieve the nearest point
$location = $this->Location->find('first', array(
'fields' => array(
'id',
'coords',
"earth_distance(coords, ll_to_earth($latitude, $longitude)) AS distance",
),
'conditions' => array(
'coords >=' => 'll_to_earth(' . ($latitude - 0.5) . ', ' . ($longitude - 0.5) . ')',
'coords <=' => 'll_to_earth(' . ($latitude + 0.5) . ', ' . ($longitude + 0.5) . ')',
),
'order' => array('distance ASC'),
));
//设置虚拟数据
$LATIONE=30.4393696;
$longitude=-97.6200043;
//在WHERE条件中创建一个简单的边界框,按位置对点进行排序,然后检索最近的点
$location=$this->location->find('first',数组(
“字段”=>数组(
“id”,
“coords”,
“地球距离(坐标,ll到地球($纬度,$经度))作为距离”,
),
“条件”=>数组(
“coords>=”=“=”、“($latitude-0.5)。”、“($latitude-0.5)。”,
“coords您应该能够这样做:
SELECT
"Location"."id" AS "Location__id",
"Location"."coords" AS "Location__coords",
earth_distance(coords, ll_to_earth(30.4393696, -97.6200043)) AS distance FROM "locations" AS "Location"
WHERE
"coords" >= 'll_to_earth(29.9393696, -97.1200043)' AND
"coords" <= 'll_to_earth(30.9393696, -96.1200043)'
ORDER BY
"distance" ASC
LIMIT 1
$location = $this->Location->find('first', array(
'fields' => array(
'id',
'coords',
"earth_distance(coords, ll_to_earth($latitude, $longitude)) AS distance",
),
'conditions' => array(
'coords >= ll_to_earth(' . ($latitude - 0.5) . ', ' . ($longitude - 0.5) . ')
and coords <= ll_to_earth(' . ($latitude + 0.5) . ', ' . ($longitude + 0.5) . ')'),
'order' => array('distance ASC'),
));
$location=$this->location->find('first',array(
“字段”=>数组(
“id”,
“coords”,
“地球距离(坐标,ll到地球($纬度,$经度))作为距离”,
),
“条件”=>数组(
'coords>=ll_to_earth('($latitude-0.5)。','($latitude-0.5)。')
还有coords facepalm哇,我已经很久没有这样做了,我忘了我可以。谢谢!