Skip to content

Instantly share code, notes, and snippets.

@tobsn
Created April 2, 2011 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tobsn/899413 to your computer and use it in GitHub Desktop.
Save tobsn/899413 to your computer and use it in GitHub Desktop.
$list_pattern = 'SELECT
%5$s AS zip,
%6$s AS name,
SQRT( (
( %2$d - %8$s ) *
( %2$d - %8$s )
) + (
( %1$d - %7$s ) *
( %1$d - %7$s )
) ) AS distance
FROM %4$s WHERE
%7$s BETWEEN
( %1$d - %3$d ) AND
( %1$d + %3$d )
AND
%8$s BETWEEN
( %2$d - %3$d ) AND
( %2$d + %3$d )
AND
SQRT( (
( %2$d - %8$s ) *
( %2$d - %8$s )
) + (
( %1$d - %7$s ) *
( %1$d - %7$s )
) ) < %3$d
ORDER BY distance ASC';
$list_query = sprintf( $list_pattern,
$list_coords[0],
$list_coords[1],
$list_range,
$this->geo_table,
$this->geo_field_zip,
$this->geo_field_name,
$this->geo_field_lat,
$this->geo_field_lon );
converting lat/lang into km - which ends up each as integer in the database!
$ko_lat_g = explode( ".", $lat );
$ko_lat = round( ( ( ( $ko_lat_g[0] * 60 ) + $ko_lat_g[1] ) * 1.852 ), 0);
$ko_lon_g = explode( '.', $lon );
$ko_lon = round(
( ( $ko_lon_g[0] * 60 ) + $ko_lon_g[1] ) *
( cos( deg2rad( $ko_lon_g[0] + ( $ko_lon_g[1] / 60 ) ) ) * 1.852 )
, 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment