예제 #1
0
 public function testSerialization()
 {
     $coordinates = array(1, 1);
     $point = new Point($coordinates);
     $expected = array('type' => 'Point', 'coordinates' => $coordinates);
     $this->assertSame('Point', $point->getType());
     $this->assertSame($coordinates, $point->getCoordinates());
     $this->assertSame($expected, $point->jsonSerialize());
 }
예제 #2
0
 /**
  * Find document near points in spherical surface
  *
  * @param string $field
  * @param float $longitude
  * @param float $latitude
  * @param int|array $distance distance from point in meters. Array distance
  *  allowed only in MongoDB 2.6
  * @return \Sokil\Mongo\Expression
  */
 public function nearPointSpherical($field, $longitude, $latitude, $distance)
 {
     $point = new Point(array((double) $longitude, (double) $latitude));
     $near = array('$geometry' => $point->jsonSerialize());
     if (is_array($distance)) {
         if (!empty($distance[0])) {
             $near['$minDistance'] = (int) $distance[0];
         }
         if (!empty($distance[1])) {
             $near['$maxDistance'] = (int) $distance[1];
         }
     } else {
         $near['$maxDistance'] = (int) $distance;
     }
     $this->where($field, array('$nearSphere' => $near));
     return $this;
 }