If you really wanted to use PostGIS:
create table places( lat_lng geography(Point,4326), place_name varchar(50) ); -- Two ways to make a geography point insert into places values (ST_MakePoint(-126.4, 45.32), 'Food Bar1'); insert into places values ('POINT(-126.4 45.32)', 'Food Bar2'); -- Spatial index create index places_lat_lng_idx on places using gist(lat_lng);
Now, to find all the places within 1 km (or 1000 m):
select *, ST_Distance(lat_lng, ST_MakePoint(-126.4, 45.32)::geography) from places where ST_DWithin(lat_lng, ST_MakePoint(-126.4, 45.32)::geography, 1000) order by ST_Distance(lat_lng, ST_MakePoint(-126.4, 45.32)::geography);
source share