[eluser]Derdiusz[/eluser]
First - convert user address to LON and LAT pair.
Next, use some Pythagoras
You probably have a table with geocodes:
Code:
CREATE TABLE GEOCODES (
address varchar(255) NOT NULL default '',
lon float default NULL,
lat float default NULL,
PRIMARY KEY (address)
);
To get geocodes from table based on distance you need make something like this:
Code:
$uLon = ...; // user longitude
$uLan = ...; // user latitude
$this->db->query("select * from geocodes order by (SQRT(POW(($uLon-lon),2)+POW(($uLat-lat),2)))")->result_array();
It based on Pythagoras: x2+y2=z2.
is a power of longitude distance (x2)
is a power of latitide distance (y2)
So, z2 (distance) is
Code:
SQRT(POW(($uLon-lon),2)+POW($uLat-lat,2))
I hope it helps and works