Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Geocoding / Radius


We have a listing of professionals and we're looking to have a user enter a zip code and find all the professionals within a radius of 100 miles of the user's zip code.
We have an existing table containing all the zip codes, counties, and cities in the US.
We also have zip codes for the physical locations of each of the professional listings.
When a user enters a zip code and radius, we need to somehow know which zip codes are within that radius.




View Complete Forum Thread with Replies

Related Forum Messages:
Zip Code Radius
I am using the following function from phpclasses.org.

How can I gues this to return also the distance for each zip code?

PHP

function inradius($zip,$radius)
    {

        $query2="SELECT * FROM zips WHERE zip='$zip'";
        $row = $db->get($query2);

            $lat=$row["lat"];
            $lon=$row["lon"];
            $query2="SELECT zipcode FROM zips WHERE (POW((69.1*(lon-"$lon")*cos($lat/57.3)),"2")+POW((69.1*(lat-"$lat")),"2"))<($radius*$radius) ";
            $result = $database->query($query2);
            if($result->count()<>0) {
                while($row = $result->fetch()) {
                    $zips[$i]=$row["zipcode"];
                    $i++;
                }
            }
        }else{
            return array();
        }
     return $zips;
    }

View Replies !
Query Which Gets Rows Based On A Radius, Lon And Lat Doesn't Work?
I have found this query which gets rows based on a radius. I need this for zip codes based on lon and lat's.

$sql2 = "SELECT * FROM table as z WHERE (SQRT( (69.1 * (".$userLat." - z.lat)) * (69.1 * (".$userLat." - z.lat)) + (53.0 *(".$userLong." - z.lon)) * (53.0 *(".$userLong." - z.lon))) <= ".$userRadius." )";
return $sql2;
$res = mysql_query($sql2, $connDB) or die(mysql_error());
$row = mysql_fetch_assoc($res);
based on a test zip code gives a result like


SELECT * FROM table as z WHERE (SQRT( (69.1 * (52.399834 - z.lat)) * (69.1 * (52.399834 - z.lat)) + (53.0 *(4.840762 - z.lon)) * (53.0 *(4.840762 - z.lon))) <= 100 )
the lat and lon of the test zip code are right. As you can see z.lat and z.lon don't get any value. And these would be every lat and lon in table.

In my db table lon and lat are decimal(10,6) type with a default value of 0.000000

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved