0

According to Mongo ODM one should be able to get distance after a near query:

http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/geospatial-queries.html#distance

When I use the near query as it shows in the documentation, I am able to get results however the distance never gets added.

Here is my query:

 $query = $dm->createQueryBuilder('SomeBundle:Blah')
        ->select('id', 'name', 'distance', 'propertyType', 'squareFootage')->field('coordinates')->near($latitude, $longitude);

$results = $query->getQuery()->execute();


foreach ($results as $city) {
    echo $city->name.': '.$city->distance."\n";
}

My distance property is set up as :

   /** @MongoDB\Distance */
    public $distance;

I get no results. Is there a bug with Mongo ODM?

Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169

1 Answers1

0

Rather than using

$query->near($latitude, $longitude);

you need to use

$query->geoNear($latitude, $longitude)

if you want distance to be populated.

Neil
  • 105
  • 1
  • 3
  • 8