<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><div id="yiv782929419"><table id="yiv782929419bodyDrftID" class="yiv782929419" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td id="yiv782929419drftMsgContent" style="font:inherit;font-family:arial;font-size:10pt;">Hi Neville,<br><br>Obviously you start by installing Postgis in your database.<br><br>Follow the instructions for your Postgis version & operating system.<br><br>To create your geometry:<br><br>1. add a geometry column to your table. This will be a point type, with a SRID of 4326 (ie: lat long degrees - see <a rel="nofollow" target="_blank" href="http://www.spatialreference.org/ref/epsg/4326/">http://www.spatialreference.org/ref/epsg/4326/</a> <br>See here for the command to use: <br><a rel="nofollow" target="_blank"
 href="http://postgis.refractions.net/docs/AddGeometryColumn.html">http://postgis.refractions.net/docs/AddGeometryColumn.html</a><br><br>2. Populate this column (called geom, for example), from your lat, lon columns with:<br>update table set geom=ST_SetSRID(ST_MakePoint(lon,lat),4326);<br>as described at <a href="http://www.postgis.org/docs/ST_MakePoint.html">http://www.postgis.org/docs/ST_MakePoint.html</a><br><br><br>You then need to make your query to retrieve the points with 7 miles of a specified location. This can get complicated depending on how accurate you want to be. The distance of 1 degree for your latitudes is 60 nautical miles. For longitude, it is 60 nm at the equator & decreases proportional to the cosine of the latitude for non-equatorial values. Postgis allows you to reproject your coordinates, or calculate against a sphere, or a selected spheroid (given the Earth is not spherical). I'm assuming here that a spherical calculation
 will work in your case, using 1/60th of a degree = 1 mile.<br><br>given a user location of $x,$y, you need to construct a point geometry & check the distance (measured on a sphere in units degrees) against each of your points, eg:<br>select * from table where ST_Distance_Sphere(ST_MakePoint($x,$y),geom) <= 7/60;<br><br>see: <a href="http://postgis.refractions.net/documentation/manual-1.4/ST_Distance_Sphere.html">http://postgis.refractions.net/documentation/manual-1.4/ST_Distance_Sphere.html</a><br><br>HTH,<br><br>  Brent Wood<br><br><br><br>--- On <b>Wed, 12/19/12, nevillekb <i><nevillekb@gmail.com></i></b>
 wrote:<br><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;"><br>From: nevillekb <nevillekb@gmail.com><br>Subject: [postgis-users] Using PostGIS for latitude & longitude<br>To: postgis-users@postgis.refractions.net<br>Date: Wednesday, December 19, 2012, 10:51 PM<br><br><div class="yiv782929419plainMail"><br>I have a table in postgresql 9.2 that stores the latitude and longitude of<br>locations as integer values.<br><br>I intend to do something like when a user searches for a location, he also<br>gets information on other locations that are within a 7 mile radius of that<br>searched location.<br><br>How do i use postGIS for this since i am new to it. Any idea.?<br><br><br><br><br>--<br>View this message in context: <a rel="nofollow" target="_blank"
 href="http://postgis.17.n6.nabble.com/Using-PostGIS-for-latitude-longitude-tp5002097.html">http://postgis.17.n6.nabble.com/Using-PostGIS-for-latitude-longitude-tp5002097.html</a><br>Sent from the PostGIS - User mailing list archive at Nabble.com.<br>_______________________________________________<br>postgis-users mailing list<br><a rel="nofollow">postgis-users@lists.osgeo.org</a><br><a rel="nofollow" target="_blank" href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br></div></blockquote></td></tr></tbody></table></div></td></tr></table>