This repository has been archived by the owner on Nov 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60750a8
commit 09e2039
Showing
2 changed files
with
35 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
|
||
/** | ||
* Adds distance from a given origin column to query. | ||
* | ||
* @param double $latitude The latitude of the origin point. | ||
* @param double $longitude The longitude of the origin point. | ||
* @param double $unit The unit measure. | ||
* | ||
* @return <?php echo $queryClassName ?> The current query, for fluid interface | ||
*/ | ||
public function withDistance($latitude, $longitude, $unit = <?php echo $defaultUnit ?>) | ||
{ | ||
if (<?php echo $peerClassName ?>::MILES_UNIT === $unit) { | ||
$earthRadius = 3959; | ||
} elseif (<?php echo $peerClassName ?>::NAUTICAL_MILES_UNIT === $unit) { | ||
$earthRadius = 3440; | ||
} else { | ||
$earthRadius = 6371; | ||
} | ||
|
||
$sql = 'ABS(%s * ACOS(%s * COS(RADIANS(%s)) * COS(RADIANS(%s) - %s) + %s * SIN(RADIANS(%s))))'; | ||
$preparedSql = sprintf($sql, | ||
$earthRadius, | ||
cos(deg2rad($latitude)), | ||
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>), | ||
$this->getAliasedColName(<?php echo $longitudeColumnConstant ?>), | ||
deg2rad($longitude), | ||
sin(deg2rad($latitude)), | ||
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>) | ||
); | ||
|
||
return $this | ||
->withColumn($preparedSql, 'Distance'); | ||
} | ||
|
||
/** | ||
* Adds distance from a given origin column to query. | ||
* | ||
* @param double $latitude The latitude of the origin point. | ||
* @param double $longitude The longitude of the origin point. | ||
* @param double $unit The unit measure. | ||
* | ||
* @return <?php echo $queryClassName ?> The current query, for fluid interface | ||
*/ | ||
public function withDistance($latitude, $longitude, $unit = <?php echo $defaultUnit ?>) | ||
{ | ||
if (<?php echo $peerClassName ?>::MILES_UNIT === $unit) { | ||
$earthRadius = 3959; | ||
} elseif (<?php echo $peerClassName ?>::NAUTICAL_MILES_UNIT === $unit) { | ||
$earthRadius = 3440; | ||
} else { | ||
$earthRadius = 6371; | ||
} | ||
|
||
$sql = 'ABS(%s * ACOS(%s * COS(RADIANS(%s)) * COS(RADIANS(%s) - %s) + %s * SIN(RADIANS(%s))))'; | ||
$preparedSql = sprintf($sql, | ||
$earthRadius, | ||
cos(deg2rad($latitude)), | ||
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>), | ||
$this->getAliasedColName(<?php echo $longitudeColumnConstant ?>), | ||
deg2rad($longitude), | ||
sin(deg2rad($latitude)), | ||
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>) | ||
); | ||
|
||
return $this | ||
->withColumn($preparedSql, 'Distance'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters