@@ 479-504 (lines=26) @@ | ||
476 | * allowed only in MongoDB 2.6 |
|
477 | * @return Expression |
|
478 | */ |
|
479 | public function nearPoint($field, $longitude, $latitude, $distance) |
|
480 | { |
|
481 | $point = new \GeoJson\Geometry\Point(array( |
|
482 | (float) $longitude, |
|
483 | (float) $latitude |
|
484 | )); |
|
485 | ||
486 | $near = array( |
|
487 | '$geometry' => $point->jsonSerialize(), |
|
488 | ); |
|
489 | ||
490 | if (is_array($distance)) { |
|
491 | if (!empty($distance[0])) { |
|
492 | $near['$minDistance'] = (int) $distance[0]; |
|
493 | } |
|
494 | if (!empty($distance[1])) { |
|
495 | $near['$maxDistance'] = (int) $distance[1]; |
|
496 | } |
|
497 | } else { |
|
498 | $near['$maxDistance'] = (int) $distance; |
|
499 | } |
|
500 | ||
501 | $this->where($field, array('$near' => $near)); |
|
502 | ||
503 | return $this; |
|
504 | } |
|
505 | ||
506 | /** |
|
507 | * Find document near points in spherical surface |
|
@@ 516-541 (lines=26) @@ | ||
513 | * allowed only in MongoDB 2.6 |
|
514 | * @return Expression |
|
515 | */ |
|
516 | public function nearPointSpherical($field, $longitude, $latitude, $distance) |
|
517 | { |
|
518 | $point = new Point(array( |
|
519 | (float) $longitude, |
|
520 | (float) $latitude |
|
521 | )); |
|
522 | ||
523 | $near = array( |
|
524 | '$geometry' => $point->jsonSerialize(), |
|
525 | ); |
|
526 | ||
527 | if (is_array($distance)) { |
|
528 | if (!empty($distance[0])) { |
|
529 | $near['$minDistance'] = (int) $distance[0]; |
|
530 | } |
|
531 | if (!empty($distance[1])) { |
|
532 | $near['$maxDistance'] = (int) $distance[1]; |
|
533 | } |
|
534 | } else { |
|
535 | $near['$maxDistance'] = (int) $distance; |
|
536 | } |
|
537 | ||
538 | $this->where($field, array('$nearSphere' => $near)); |
|
539 | ||
540 | return $this; |
|
541 | } |
|
542 | ||
543 | /** |
|
544 | * Selects documents whose geospatial data intersects with a specified |