Welcome Guest, Not a member yet? Register   Sign In
zip code radius search
#1

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
Reply
#2

(This post was last modified: 09-06-2016, 12:04 PM by dmyers.)

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
Reply
#3

(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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB