我想实现这一目标
SELECT id,( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0,20;
从https://developers.google.com/maps/articles/phpsqlsearch_v3?hl=fr#createtable
如何使用Bookshelf进行此查询.
我现在有这个:
var raw = '( 3959 * acos( cos( radians(37) ) * cos( radians( '+ req.params.lat + ' ) ) * cos( radians( '+req.params.lng+' ) - radians(-122) ) + sin( radians(37) ) * sin( radians( '+req.body.lng+' ) ) ) ) AS distance'; new Places().query(function(qb) { qb.where('lat',req.params.lat); qb.where('lng',req.params.lng); qb.column(raw); qb.having('distance','>',25); }).fetch({ debug: false }).then(function(collection) { console.log(collection); if (collection === undefined) { // no such result res.json(404,{error: "No Places found."}); } else { // found,list json res.json(200,collection); } });