Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

GeoCode

DZone's Guide to

GeoCode

·
Free Resource
//Mysql!


set @orig_lat=38.70032 ;
set @orig_lon=-9.38603;

/*Meters*/
set @dist=10;

set @mylat = @orig_lat;
set @mylon = @orig_lon;

/*1º = 69miles = 111Km or 111000 meters*/
set @unit = 111000;

set @lon1 = @mylon - @dist/abs(cos(radians(@mylat))*@unit);
set @lon2 = @mylon + @dist/abs(cos(radians(@mylat))*@unit);
set @lat1 = @mylat - (@dist/@unit);
set @lat2 = @mylat + (@dist/@unit);

SELECT 
  id, slug, latitude, longitude, councilId, @lon1, @lon2, @lat1, @lat2, @orig_lat, @orig_lon, @dist, @mylat, @mylon 
from 
  entity
where
    latitude
      between
        @lat1 AND @lat2
  AND
    longitude
      between
        @lon1 AND @lon2;

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}