|
1 | | - |
2 | | -/** |
3 | | - * Adds distance from a given origin column to query. |
4 | | - * |
5 | | - * @param double $latitude The latitude of the origin point. |
6 | | - * @param double $longitude The longitude of the origin point. |
7 | | - * @param double $unit The unit measure. |
8 | | - * |
9 | | - * @return <?php echo $queryClassName ?> The current query, for fluid interface |
10 | | - */ |
11 | | -public function withDistance($latitude, $longitude, $unit = <?php echo $defaultUnit ?>) |
12 | | -{ |
13 | | - if (<?php echo $peerClassName ?>::MILES_UNIT === $unit) { |
14 | | - $earthRadius = 3959; |
15 | | - } elseif (<?php echo $peerClassName ?>::NAUTICAL_MILES_UNIT === $unit) { |
16 | | - $earthRadius = 3440; |
17 | | - } else { |
18 | | - $earthRadius = 6371; |
19 | | - } |
20 | | - |
21 | | - $sql = 'ABS(%s * ACOS(%s * COS(RADIANS(%s)) * COS(RADIANS(%s) - %s) + %s * SIN(RADIANS(%s))))'; |
22 | | - $preparedSql = sprintf($sql, |
23 | | - $earthRadius, |
24 | | - cos(deg2rad($latitude)), |
25 | | - $this->getAliasedColName(<?php echo $latitudeColumnConstant ?>), |
26 | | - $this->getAliasedColName(<?php echo $longitudeColumnConstant ?>), |
27 | | - deg2rad($longitude), |
28 | | - sin(deg2rad($latitude)), |
29 | | - $this->getAliasedColName(<?php echo $latitudeColumnConstant ?>) |
30 | | - ); |
31 | | - |
32 | | - return $this |
33 | | - ->withColumn($preparedSql, 'Distance'); |
34 | | -} |
| 1 | + |
| 2 | +/** |
| 3 | + * Adds distance from a given origin column to query. |
| 4 | + * |
| 5 | + * @param double $latitude The latitude of the origin point. |
| 6 | + * @param double $longitude The longitude of the origin point. |
| 7 | + * @param double $unit The unit measure. |
| 8 | + * |
| 9 | + * @return <?php echo $queryClassName ?> The current query, for fluid interface |
| 10 | + */ |
| 11 | +public function withDistance($latitude, $longitude, $unit = <?php echo $defaultUnit ?>) |
| 12 | +{ |
| 13 | + if (<?php echo $peerClassName ?>::MILES_UNIT === $unit) { |
| 14 | + $earthRadius = 3959; |
| 15 | + } elseif (<?php echo $peerClassName ?>::NAUTICAL_MILES_UNIT === $unit) { |
| 16 | + $earthRadius = 3440; |
| 17 | + } else { |
| 18 | + $earthRadius = 6371; |
| 19 | + } |
| 20 | + |
| 21 | + $sql = 'ABS(%s * ACOS(%s * COS(RADIANS(%s)) * COS(RADIANS(%s) - %s) + %s * SIN(RADIANS(%s))))'; |
| 22 | + $preparedSql = sprintf($sql, |
| 23 | + $earthRadius, |
| 24 | + cos(deg2rad($latitude)), |
| 25 | + $this->getAliasedColName(<?php echo $latitudeColumnConstant ?>), |
| 26 | + $this->getAliasedColName(<?php echo $longitudeColumnConstant ?>), |
| 27 | + deg2rad($longitude), |
| 28 | + sin(deg2rad($latitude)), |
| 29 | + $this->getAliasedColName(<?php echo $latitudeColumnConstant ?>) |
| 30 | + ); |
| 31 | + |
| 32 | + return $this |
| 33 | + ->withColumn($preparedSql, 'Distance'); |
| 34 | +} |
0 commit comments