Ich habe einen folgenden Code, der diese Lat zurückgeben sollte, lange in Mongodb, die in der Nähe der genannten sind. Aber das Problem ist, dass es alle Lat, Longs zurückgibt.in der Nähe gibt alle Dokumente in einer Sammlung zurück
$collection->ensureIndex(array("location" => "2d"));
$a=array(24.8934,67.0281);
//print_r($a);
$distance='500';
$query = array('location' => array('$near' => array(24.8934,67.0281)));
$cursor = $collection->find($query);
try{
if ($cursor) {
echo $arr= json_encode(iterator_to_array($cursor));
// $j= json_decode($arr,false);
echo var_dump(json_decode($arr));
$j = json_decode($arr,false);
$lat= $j->{'57237036d89c45e1e3fda94e'}->location[0];
$lng= $j->{'57237036d89c45e1e3fda94e'}->location[1];
} else {
echo "{ 'status' : 'false' }";
}
Es gibt die folgende:
object(stdClass)[7]
public '572453d55addfab49090ea71' =>
object(stdClass)[6]
public '_id' =>
object(stdClass)[8]
public '$id' => string '572453d55addfab49090ea71' (length=24)
public 'location' =>
array (size=2)
0 => float 24.8615
1 => float 67.0099
public '57237036d89c45e1e3fda94e' =>
object(stdClass)[9]
public '_id' =>
object(stdClass)[10]
public '$id' => string '57237036d89c45e1e3fda94e' (length=24)
public 'location' =>
array (size=2)
0 => float 33.7715
1 => float 72.7511
Statt nur das erste Dokument zurückkehren sollte.