ckroon
Posts: 869
|
| Posted: 08/16/2007, 8:03 PM |
|
I have a client that wants a component that will allow you to select a student from a list, then display the teachers(user table) that live within 10 miles of that students zipcode.
I have seen applications that take care of the zipcode thing, but nothing that would fit into CCS.
Anyone care to point me in the right direction? Swift kicks int he right direction are also appreciated.
Thanks!
_________________
Walter Kempees...you are dearly missed. |
 |
 |
TonyReid
Posts: 159
|
| Posted: 08/17/2007, 12:19 AM |
|
Id probably use something like google maps to do that.
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk |
 |
 |
wkempees
Posts: 1679
|
| Posted: 08/17/2007, 5:03 AM |
|
I asked one of my friends how to do this.
result: 10+ pages
Google: zipcode distance http://webservices.imacination.com/distance/
http://www.freedownloadscenter.com/Business/Application...nce_Wizard.html
gives you a wizard withj ability to create csv file, from there on......
More difficult, I need the same on Dutch postal codes
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
DonB
|
| Posted: 08/17/2007, 5:27 AM |
|
It's a two step solution: (1) geocode the address/zipcode to determine
lat/log of center point; (2) evaluate the lat/long result against your
database:
(fragment of code showing the SQL which locates points within a specified
radius)
# If we don't have a long/lat pair BUT we have a radius (in miles), try
to geocode the address string if we have that
if (isset($dist['miles']) &&
isset($dist['addr']) &&
(!isset($dist['lat']) || !isset($dist['lng'])))
{
$latlng = geocoder($dist['addr']);
$dist['lat'] = $latlng['latitude'];
$dist['lng'] = $latlng['longitude'];
}
# Now if we have all three values, construct the portions of our query
that query within the radius specified
if (isset($dist['miles']) &&
isset($dist['lat']) &&
isset($dist['lng'])) {
$where = "(((acos(sin((" . $dist['lat'] . " * pi()/180)) *
sin((Latitude*pi()/180))" .
" + cos((" . $dist['lat'] . " * pi()/180)) *
cos((Latitude*pi()/180)) * cos(((" . $dist['lng'] .
" - Longitude) * pi()/180)))) * 180/pi())*60*1.1515) <= " .
$dist['miles'] .
" AND Latitude IS NOT NULL AND Longitude IS NOT NULL";
$radius = "HAVING distance <= " . $dist['miles'];
}
(assemble $where, $radius into a query against the database to find points
within circle defined by reference point and radius)
function geocoder($address) {
# $address is string, eg 'street city state zipcode' GoogleMapKey is key
code generated by Google that is unique for each website URL
$url = "http://maps.google.com/maps/geo?q=" . urlencode($address) .
"&output=csv&key=" . GoogleMapKey;
if ($ch = curl_init()) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); # Return requested page into
a variable
curl_setopt($ch, CURLOPT_URL, $url);
$latlong = curl_exec($ch);
curl_close($ch);
# $latlong value is 4 items: statuscode, accuracy, latitude, longitude
# Clean it up before returning it:
$latlong = explode(",",$latlong);
if (count($latlong) == 4) {
$status = array_shift($latlong);
$precis = array_shift($latlong);
if ($status == 200) {
$lat = array_shift($latlong);
$long = array_shift($latlong);
return array('latitude'=>$lat,'longitude'=>$long);
}
else
return false; # Unable to get data
} # count
} #$ch
}
--
DonB
http://ccswiki.gotodon.net
"ckroon" <ckroon@forum.codecharge> wrote in message
news:546c50fecc4ba9@news.codecharge.com...
> I have a client that wants a component that will allow you to select a
student
> from a list, then display the teachers(user table) that live within 10
miles of
> that students zipcode.
>
> I have seen applications that take care of the zipcode thing, but nothing
that
> would fit into CCS.
>
> Anyone care to point me in the right direction? Swift kicks int he right
> direction are also appreciated.
>
> Thanks!
>
>
>
>
>
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
datadoit.com
|
| Posted: 08/17/2007, 6:32 AM |
|
Where can one wrap their hands around this geocode database?
|
|
|
 |
TonyReid
Posts: 159
|
| Posted: 08/17/2007, 7:01 AM |
|
I am sure I have a zipcode database with long/lat coordinates somewhere at home if you want it.
Might take me some time to dig out.
Although I do not know how up to date it is.
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk |
 |
 |
Benjamin Krajmalnik
|
| Posted: 08/17/2007, 7:26 AM |
|
http://www.files-library.com/files/GeoCalc-PHP.html
The sample files show hot to do it.
Not difficult at all. All the functios are there. I think that the default
only had conversion to km.
I added 2 more functins to convert lat and lon degtress to miles.
Proces is simple.
1. Look up lat and lon for zip code.
2. Get deg lat and deg lon per mile.
3. Multiply deg lat and deg lon times distance (this will tell you the +/-
delta to be applied).
4 Your query should now be modified to return all records where the
latitude/logitude is between the min/max values.
Remember that this is a square bounding box, not a radius, but it is good
enough. Esp[ecially since the zipcode database only gives you one point for
the entire zipcode.
"datadoit.com" <datadoit@forum.codecharge> wrote in message
news:fa481u$rpg$1@news.codecharge.com...
> Where can one wrap their hands around this geocode database?
|
|
|
 |
DonB
|
| Posted: 08/17/2007, 9:00 AM |
|
I normally just run the geocoding on addresses as they go into the database
(Before Build Insert event), to get their lat/long, and then store it so the
geocoding doesn't need to be done but once. Or you could run through an
existing database and update that. Thus I'm relying on the Google database
for the coordinates. (There are several public geocoding interfaces besides
Google's)
The Post Office offers a database of zips and lat/long, and I've seen from
time-to-time where other people have published similar lists. I believe the
USPS charges a 100-200 bucks for theirs. But you don't really need either
one.
--
DonB
http://ccswiki.gotodon.net
"datadoit.com" <datadoit@forum.codecharge> wrote in message
news:fa481u$rpg$1@news.codecharge.com...
> Where can one wrap their hands around this geocode database?
|
|
|
 |
ckroon
Posts: 869
|
| Posted: 08/17/2007, 9:04 AM |
|
Hi guys, thanks for all the tips.
From my own investigation I found this: www.buyzips.com
The Platinum series has Lat and Long coordinates.
Apparently you have to use some trigonometry to inverse between the zipcodes to get the mile distance (this is what I'm told).
There are other sources of zip code database and they come with yearly updates as well, but this one seemed the best.
And here is where Walter can get his Zp codes with coordinates:
http://www.koordinaten.de/english/online/zip.shtml
_________________
Walter Kempees...you are dearly missed. |
 |
 |
Benjamin Krajmalnik
|
| Posted: 08/17/2007, 10:27 AM |
|
The geo class I posted has that in there already for you.
It actually does a lot more than that.
"ckroon" <ckroon@forum.codecharge> wrote in message
news:546c5c6f30d8bf@news.codecharge.com...
> Hi guys, thanks for all the tips.
>
> From my own investigation I found this: www.buyzips.com
>
> The Platinum series has Lat and Long coordinates.
> Apparently you have to use some trigonometry to inverse between the
> zipcodes to
> get the mile distance (this is what I'm told).
>
> There are other sources of zip code database and they come with yearly
> updates
> as well, but this one seemed the best.
>
>
>
>
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
datadoit.com
|
| Posted: 08/17/2007, 11:22 AM |
|
Benjamin Krajmalnik wrote:
> The geo class I posted has that in there already for you.
> It actually does a lot more than that.
>> ---------------------------------------
I did not see the database in this file. Unless I missed something. I
grabbed the database from here:
http://sourceforge.net/projects/zips/
|
|
|
 |
Benjamin Krajmalnik
|
| Posted: 08/17/2007, 8:51 PM |
|
You can use a database from any source you want, since it is a class.
If you send me a private email to kraj at illumen dot com I can send you a
csv file of all of the codes which you can import ito your own database.
That particular file you are referring to is a bit dated. For example, the
zip code where my ofice resides is not there.
"datadoit.com" <datadoit@forum.codecharge> wrote in message
news:fa4p0q$9kr$1@news.codecharge.com...
> Benjamin Krajmalnik wrote:
>> The geo class I posted has that in there already for you.
>> It actually does a lot more than that.
>>> ---------------------------------------
>
> I did not see the database in this file. Unless I missed something. I
> grabbed the database from here:
>
> http://sourceforge.net/projects/zips/
|
|
|
 |
datadoit.com
|
| Posted: 08/18/2007, 5:55 AM |
|
Is there a free web service out yonder some where? Maybe this is what
Google does?
|
|
|
 |
DonB
|
| Posted: 08/18/2007, 7:48 AM |
|
That's pretty much what Google does. If you go to http://maps.google.com/
and put in just a zipcode, you'll get (pretty close) the location of the
post office for that zip, which is what these 'zipcode databases' typically
contain. They probably trace back to the same 1st generation source from
the USPS so that's not really surprising.
--
DonB
http://www.gotodon.com/ccbth
"datadoit.com" <datadoit@forum.codecharge> wrote in message
news:fa6q7c$i60$1@news.codecharge.com...
> Is there a free web service out yonder some where? Maybe this is what
> Google does?
|
|
|
 |