Skip to content

Instantly share code, notes, and snippets.

@zuckercode
Created October 23, 2012 22:26
Show Gist options
  • Save zuckercode/3942110 to your computer and use it in GitHub Desktop.
Save zuckercode/3942110 to your computer and use it in GitHub Desktop.
opengeodb select
/* select one test zip */
SELECT zc_id, zc_location_name, zc_lat, zc_lon
FROM zip_coordinates
WHERE zc_zip = '13187';
/* calculate with the found data from above the zip in the radius < 20km */
SELECT
zc_zip,
zc_location_name,
ACOS(
SIN(RADIANS(zc_lat)) * SIN(RADIANS(52.5710506114498))
+ COS(RADIANS(zc_lat)) * COS(RADIANS(52.5710506114498)) * COS(RADIANS(zc_lon)
- RADIANS(13.4049687142945))
) * 6380 AS distance
FROM zip_coordinates
WHERE ACOS(
SIN(RADIANS(zc_lat)) * SIN(RADIANS(52.5710506114498))
+ COS(RADIANS(zc_lat)) * COS(RADIANS(52.5710506114498)) * COS(RADIANS(zc_lon)
- RADIANS(13.4049687142945))
) * 6380 < 20
AND zc_id <> 9739
ORDER BY distance,zc_zip;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment