Geospatial Queries

You can execute some special queries when using geospatial indexes like checking for documents within a rectangle or circle.


First, setup some documents like the following:

  • PHP
     * @Document
     * @Index(keys={"coordinates"="2d"})
    class City
        /** @Id */
        public $id;
        /** @Field(type="string") */
        public $name;
        /** @EmbedOne(targetDocument="Coordinates") */
        public $coordinates;
    /** @EmbeddedDocument */
    class Coordinates
        /** @Field(type="float") */
        public $x;
        /** @Field(type="float") */
        public $y;
  • XML
            <key name="coordinates" order="2d" />

Near Query

Now you can execute queries against these documents like the following. Check for the 10 nearest cities to a given longitude and latitude with the near($longitude, $latitude) method:


$cities = $this->dm->createQuery('City')
    ->field('coordinates')->near(-120, 40)

Project Versions

Table Of Contents

This Page

Fork me on GitHub