Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save atomoc/b083b7efa3da57bca6a8f846a8f7b96b to your computer and use it in GitHub Desktop.
Save atomoc/b083b7efa3da57bca6a8f846a8f7b96b to your computer and use it in GitHub Desktop.
<?php
function LatLngDist($p, $q) {
$R = 6371; // Earth radius in km
$dLat = (($q[0] - $p[0]) * pi() / 180);
$dLon = (($q[1] - $p[1]) * pi() / 180);
$a = sin($dLat / 2) * sin($dLat / 2) +
cos($p[0] * pi() / 180) * cos($q[0] * pi() / 180) *
sin($dLon / 2) * sin($dLon / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return $R * $c;
}
@atomoc
Copy link
Author

atomoc commented Jul 28, 2016

Пример использования:

if ( LatLngDist(explode(',', $page['map']), explode(',', $row['map'])) > 9 ){ // Будут отсеяны все объекты, расстояние которых больше чем 9 км от данного объекта
        continue;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment