CodeIgniter Forums

Full Version: zip code radius search
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, wondering if anyone has a CI3 example, library or suggestion for a zip code radius search.

There seems to be plenty of general examples on the WWW, but thought I'd ask if anyone has any good feedback on a CI-enabled solution.

Donovan
Something like this in your model


PHP Code:
function zipcodeRadius($lat$lon$radius)
{
   $radius $radius $radius 20;
   $sql 'SELECT distinct(ZipCode) FROM zipcode  WHERE (3958*3.1415926*sqrt((Latitude-'.$lat.')*(Latitude-'.$lat.') + cos(Latitude/57.29578)*cos('.$lat.'/57.29578)*(Longitude-'.$lon.')*(Longitude-'.$lon.'))/180) <= '.$radius.';';
   $result $this->db->query($sql);
   // get each result
   $zipcodeList = array();
   while($row $this->db->fetch_array($result))
   {
       array_push($zipcodeList$row['ZipCode']);
   }
   return $zipcodeList;


Of course it will require that you have all of your zipcodes lat/lon encoded in the database.


http://stackoverflow.com/questions/24105...ity-search

DMyers
(09-06-2016, 12:03 PM)dmyers Wrote: [ -> ]Something like this in your model


PHP Code:
function zipcodeRadius($lat$lon$radius)
{
   $radius $radius $radius 20;
   $sql 'SELECT distinct(ZipCode) FROM zipcode  WHERE (3958*3.1415926*sqrt((Latitude-'.$lat.')*(Latitude-'.$lat.') + cos(Latitude/57.29578)*cos('.$lat.'/57.29578)*(Longitude-'.$lon.')*(Longitude-'.$lon.'))/180) <= '.$radius.';';
   $result $this->db->query($sql);
   // get each result
   $zipcodeList = array();
   while($row $this->db->fetch_array($result))
   {
       array_push($zipcodeList$row['ZipCode']);
   }
   return $zipcodeList;


Of course it will require that you have all of your zipcodes lat/lon encoded in the database.


http://stackoverflow.com/questions/24105...ity-search

DMyers


Thanks!