Last active
April 7, 2016 08:15
-
-
Save tqyq/e2a990915f1288068727 to your computer and use it in GitHub Desktop.
php mongodb geo index query by loc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run below in mongo client shell | |
db.teacher.createIndex( { "loc": "2d" } ) | |
// php query | |
public function test($dis=1) { | |
$r = D('Teacher')->command([ | |
'geoNear'=>'teacher', | |
'near'=>[116.32723, 39.977331], | |
'maxDistance' => $dis/111, | |
'distanceMultiplier' => 111, | |
'num' => 2000, | |
'query'=>['audit'=>'1'], | |
]); | |
json_out($r); | |
} | |
// another example | |
$mongo = new Mongo(); | |
$result = $mongo->selectDB('users')->command(array( | |
'geoNear' => 'user', | |
'near' => $lnglat, | |
'spherical' => true, | |
'num' => 10 )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment