Welcome Guest, Not a member yet? Register   Sign In
zip code radius search
#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


Messages In This Thread
zip code radius search - by dbrooke - 09-06-2016, 08:16 AM
RE: zip code radius search - by dmyers - 09-06-2016, 12:03 PM
RE: zip code radius search - by dbrooke - 09-07-2016, 08:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB