DEV Community

Discussion on: Calculate Distance between 2 Geo Locations in PHP MySQL

Collapse
 
iacons profile image
Iacovos Constantinou

Another option is to use ST_Distance_Sphere which is available since MySQL 5.7 . The example provided could be rewritten as per below:

$sql = "SELECT ST_Distance_Sphere(point($user_longitude, $user_latitude), point(longitude, latitude) FROM geo_cord WHERE distance <= $distance"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
techmesh profile image
Deepak Singh

Indeed... Thanks for the heads up!