Kenneth Palaganas - 2 months ago 23x
PHP Question

# How to check if a certain coordinates fall to another coordinates radius using PHP only

I have seen some functions but it happens only in MySQL or Postgresql
But what I want is the equivalent when doing only in PHP? I just doing some comparison,
Like I have this data that is produced when created.

``````Lat: 56.130366
Long: -106.34677099999
``````

Later on, I want to check if that data coordinates will fall within the radius of the following coordinates. Like If data1 is within the data2 radius then return true otherwise false.

``````Lat: 57.223366
Long: -106.34675644699
``````

Thanks for the help. Below is an example function that takes two sets of longitude and latitude co-ordinates and returns the distance between the two.

``````function getDistance( \$latitude1, \$longitude1, \$latitude2, \$longitude2 ) {

\$dLat = deg2rad( \$latitude2 - \$latitude1 );
\$dLon = deg2rad( \$longitude2 - \$longitude1 );

\$a = sin(\$dLat/2) * sin(\$dLat/2) + cos(deg2rad(\$latitude1)) * cos(deg2rad(\$latitude2)) * sin(\$dLon/2) * sin(\$dLon/2);
\$c = 2 * asin(sqrt(\$a));