@@ 453-478 (lines=26) @@ | ||
450 | * allowed only in MongoDB 2.6 |
|
451 | * @return \Sokil\Mongo\Expression |
|
452 | */ |
|
453 | public function nearPoint($field, $longitude, $latitude, $distance) |
|
454 | { |
|
455 | $point = new \GeoJson\Geometry\Point(array( |
|
456 | (float) $longitude, |
|
457 | (float) $latitude |
|
458 | )); |
|
459 | ||
460 | $near = array( |
|
461 | '$geometry' => $point->jsonSerialize(), |
|
462 | ); |
|
463 | ||
464 | if(is_array($distance)) { |
|
465 | if(!empty($distance[0])) { |
|
466 | $near['$minDistance'] = (int) $distance[0]; |
|
467 | } |
|
468 | if(!empty($distance[1])) { |
|
469 | $near['$maxDistance'] = (int) $distance[1]; |
|
470 | } |
|
471 | } else { |
|
472 | $near['$maxDistance'] = (int) $distance; |
|
473 | } |
|
474 | ||
475 | $this->where($field, array('$near' => $near)); |
|
476 | ||
477 | return $this; |
|
478 | } |
|
479 | ||
480 | /** |
|
481 | * Find document near points in spherical surface |
|
@@ 490-515 (lines=26) @@ | ||
487 | * allowed only in MongoDB 2.6 |
|
488 | * @return \Sokil\Mongo\Expression |
|
489 | */ |
|
490 | public function nearPointSpherical($field, $longitude, $latitude, $distance) |
|
491 | { |
|
492 | $point = new Point(array( |
|
493 | (float) $longitude, |
|
494 | (float) $latitude |
|
495 | )); |
|
496 | ||
497 | $near = array( |
|
498 | '$geometry' => $point->jsonSerialize(), |
|
499 | ); |
|
500 | ||
501 | if(is_array($distance)) { |
|
502 | if(!empty($distance[0])) { |
|
503 | $near['$minDistance'] = (int) $distance[0]; |
|
504 | } |
|
505 | if(!empty($distance[1])) { |
|
506 | $near['$maxDistance'] = (int) $distance[1]; |
|
507 | } |
|
508 | } else { |
|
509 | $near['$maxDistance'] = (int) $distance; |
|
510 | } |
|
511 | ||
512 | $this->where($field, array('$nearSphere' => $near)); |
|
513 | ||
514 | return $this; |
|
515 | } |
|
516 | ||
517 | /** |
|
518 | * Selects documents whose geospatial data intersects with a specified |