Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
distancecalculator.php
1<?php
2
4
6
13{
14 private const EARTH_RADIUS = 6371;
15
21 public function calculate(Location $location1, Location $location2)
22 {
23 if(
24 empty($location1->getLatitude())
25 || empty($location1->getLongitude())
26 || empty($location2->getLatitude())
27 || empty($location2->getLongitude())
28 )
29 {
30 return false;
31 }
32
33 $lat1 = $location1->getLatitude() / 180 * M_PI;
34 $lat2 = $location2->getLatitude() / 180 * M_PI;
35 $lon1 = $location1->getLongitude() / 180 * M_PI;
36 $lon2 = $location2->getLongitude() / 180 * M_PI;
37
38 return (float)acos(sin($lat1)*sin($lat2)
39 + cos($lat1)*cos($lat2)
40 * cos($lon2-$lon1))
41 * self::EARTH_RADIUS;
42 }
43}
calculate(Location $location1, Location $location2)