//Сначала подключаем GeoIp для определения текущего местоположения пользователя use \Bitrix\Main\Service\GeoIp;
// получаем ip пользователя
$userIpAddress = GeoIp\Manager::getRealIp();
$lt = GeoIp\Manager::getGeoPositionLatitude($userIpAddress, "ru"); // возвращает широту
$ln = GeoIp\Manager::getGeoPositionLongitude($userIpAddress, "ru"); // возвращает долготу
// класс рассчета ближайшего расстояния
class Point
{
public $x, $y;
function __construct($x, $y)
{
$this->x = $x;
$this->y = $y;
}
function distanceTo(Point $point)
{
$distanceX = $this->x - $point->x;
$distanceY = $this->y - $point->y;
$distance = sqrt($distanceX * $distanceX + $distanceY * $distanceY);
return $distance;
}
function __toString()
{
return 'x: ' . $this->x . ', y: ' . $this->y;
}
}
// в примере мы рассматриваем расстояние до