Created
January 23, 2024 14:00
-
-
Save erdum/9464025a720ae228d90cc5374e531eae to your computer and use it in GitHub Desktop.
Check two geo-coordinate points are within a specified range
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
<?php | |
check_in_distance($lat_a, $long_a, $lat_b, $long_b, $range) | |
{ | |
$dlat = ($lat_a / (180 / pi())) - ($lat_b / (180 / pi())); | |
$dlong = ($long_a / (180 / pi())) - ($long_b / (180 / pi())); | |
$c = pow(sin($dlat / 2), 2) + cos($lat_a); | |
$c = $c * cos($lat_b) * pow(sin($dlong / 2), 2); | |
$c = 2 * asin(sqrt($c)); | |
$c = 6371 * $c; | |
return $c <= $range; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment