geo_mysql_spatial_query_distance

geo/db/mysql_spatial.inc, line 61

Versions
6
geo_mysql_spatial_query_distance($field, $srid, $point)

Calculate the distance using the Pythagorean theorem. It's cheaper than the spherical versions, but less accurate. TODO only works for points - the X() and Y() functions should be supplanted by something that's cognizant of other geometries.

Code

<?php
function geo_mysql_spatial_query_distance($field, $srid, $point) {
  // Point data.
  $x = $point['lon'];
  $y = $point['lat'];

  // Offsets, in meters.
  $mod_x = GEO_DEGREE_M * cos($y / 57.2958);
  $mod_y = GEO_DEGREE_M; 

  return "SQRT(POW(($mod_x * (X($field) - $x)), 2) + POW(($mod_y * (Y($field) - $y)), 2))";
}
?>