Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Zip Code Lookup

New Here ,
Oct 04, 2008 Oct 04, 2008
Hi guys,

Ok, I've had a project dumped on me that is ridiculously complicated given my level of ability. I've explained to them that I am NOT the guy for this. They're in a real jam though, so while they're trying to find someone else I told them I'd see what I can do.

Basically, it's a political action page. You watch a short flash video, then click a button to send email to the candidates running to represent you. It's been built (kind of) using PHP by someone else, but has so many bugs (and I don't know anything about PHP) that I think my only hope is to try and re-write the whole thing in Coldfusion (which I know the basics of).

Thankfully the mySQL database is already done and working. I just need to build the pages. The real sticking point: on the "tell a candidate" page, they want a user to fill out their street address, click a button, and have the application automatically find their full zipcode and then display a page listing the candidates running to represent that district (this is limited to one state, thank god).

I can handle the database-driven stuff to return email links for their candidates (I think)... but how can I use Coldfusion to find a person's full zipcode based on their street address?

Thanks for ANY ideas... the more dumbed-down the better!
Joe
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2008 Oct 04, 2008
> I can handle the database-driven stuff to return email links for their
> candidates (I think)... but how can I use Coldfusion to find a person's
> full
> zipcode based on their street address?

Well there are people that sell this type of information,
http://www.zip-codes.com/zip-code-database.asp
but these days, everyone knows their zip code (at least the first 5) and
I would convince the client to skip the zip code look up and go straight to
the candidate look up based on zip code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2008 Oct 04, 2008
Yeah, see, that's the problem. The districts in Maine don't always fracture along 5 digit zip codes... you need the WHOLE thing or you risk people sending email to candidates that don't represent them. The page is currently designed to run a PHP script that actually works: you enter your street address: "1234 My St., Portland, ME" and it automatically finds your full zipcode and displays your candidates. Apparently the client is stuck on this functionality.

So the PHP script is working. It looks to use an online database or service here: " http://local.yahooapis.com/MapsService/V1/geocode".

The problem is, so much of the rest of the site is a mess, and I can't fix the PHP, that I was hoping to port this capability over to CF. I'd gladly buy a CF component to do this, if someone has one.

Thanks for ANY ideas...
Joe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2008 Oct 05, 2008
It's no big deal, StearmanDriver. You already have a good solution. Yahoo!

All you have to do is get a Yahoo App ID. You can then use it with, for example, the cfhttp tag to get the zip code. The service is free, too.

Suppose your Yahoo App ID is vmuNNhtDEr32Ms8pmwEyvoAdClQQabcploMMth2iY_GXMK456Mruav56P09iuQk7.BBFtC--. (This is a fake ID I've just created to illustrate the process. But it is similar to the one Yahoo will send you.) Suppose also that you wished to know the zip code of the Hilton Garden Inn Hotel in Commercial Street, Portland, Maine.

The result, cfhttp.FileContent, is a short XML document. However, it gives you more bang for your buck (see actual result below). It includes, besides the zip, the latitude and longitude of the place.

To get the zip code, simply parse the XML. The complete code is something like the one below.





actual result, cfhttp.fileContent:
<?xml version="1.0" ?>
<ResultSet xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
<Result precision="address">
<Latitude>43.657646</Latitude>
<Longitude>-70.250313</Longitude>
<Address>65 Commercial St</Address>
<City>Portland</City>
<State>ME</State>
<Zip>04101-4703</Zip>
<Country>US</Country>
</Result>
</ResultSet>
<!-- ws07.search.re2.yahoo.com compressed/chunked Sun Oct 5 00:10:51 PDT 2008

-->


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2008 Oct 05, 2008
It's funny... the PHP code that accomplishes basically the same as
your example is like 3 pages long. I don't know if that's due to the
developer who wrote it, or just the fact that it's PHP, but the CF looks
soo much simpler.

Yeah, Joe! That is how we do it!

One question, before I get too far into this and then realize
I'm chasing a dead end: can you confirm that this Yahoo service
will return a full zipcode with JUST a street address entered,
and NO zipcode? For instance, in your example, "65 Commercial st.,
Portland, ME" run through the service will return the full zip?

Take a look at cfhttp's url attribute. There is indeed no zipcode required. That's the whole point. It is a zipcode lookup service.

Now, let's beef it up a little. Let's supply the name, address and city dynamically. I ran the code below, using my own ID, and got the following result:

name: Portland City Hall
Zip Code: 04101-3503

name: Newick's Seafood Restaurant
Zip Code: 04106-4408

name: Tate House Museum
Zip Code: 04102-1917

name: Disney Studios
Zip Code: 91505-0001

name: The White House
Zip Code: 20006


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 05, 2008 Oct 05, 2008
Hey, THANKS, BK.

I was doing a little digging myself into the Yahoo APIs, and you've answered my next question before I even asked it.

I don't 100% understand your post because I'm not real familiar with xml, but it looks pretty straightforward. I'm gonna study up on it tonight and see where I'm at.

It's funny... the PHP code that accomplishes basically the same as your example is like 3 pages long. I don't know if that's due to the developer who wrote it, or just the fact that it's PHP, but the CF looks soo much simpler.

One question, before I get too far into this and then realize I'm chasing a dead end: can you confirm that this Yahoo service will return a full zipcode with JUST a street address entered, and NO zipcode? For instance, in your example, "65 Commercial st., Portland, ME" run through the service will return the full zip?

If so, awesome, I might actually be able to do this!

Joe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2008 Oct 06, 2008
Ok, I've got a basic version of this working. Thanks again, BK.

Is there a way to strip the hyphen out of the zip code by chance? The database the last developer built has the zips as 9 digit intgers with no formatting. It'd be easier to match if I could pull the hyphen out of the Yahoo result.

If not, they're close enough and I'll make it work.
Thanks again!
Joe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2008 Oct 06, 2008
have you heard the cf's replace() function?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2008 Oct 06, 2008
Well... I have now, thanks! I knew there'd be a simple way.

I apologize for the dumb questions. I'd ordinarily research this stuff on my own, but this app is pretty time-critical. I'm just doing it as a favor but I still feel responsible for getting it done quickly... so I really appreciate everyone's help.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2008 Oct 06, 2008
Ok... I'm having trouble making the replace() function work with the #zipcode# variable. Any chance someone could post an example using BKBK's original code from above:

<cfhttp url=" http://local.yahooapis.com/MapsService/V1/geocode?appid=vmuNNhtDEr32Ms8pmwEyvoAdClQQabcploMMth2iY_GX... method="get" throwonerror="false" timeout="5">
<!--- <cfdump var="#cfhttp.FileContent#"> --->
<cfxml variable="addressObj">
<cfoutput>#cfhttp.FileContent#</cfoutput>
</cfxml>
<cfset zipCode = addressObj["ResultSet"]["Result"]["Zip"].XmlText>
Zip Code (Hilton Garden Inn Hotel, Portland, Maine): <cfoutput>#zipCode#</cfoutput>

Thanks...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2008 Oct 07, 2008
All right, I was hoping I could figure out the application flow here, but in the interest of saving time I'm gonna ask for suggestions on that too... No code examples needed (unless you want), I'm just looking for basic ideas. I need to:

1. Take a form-entered street address and find zipcode (got this part working already.)
2. Use that zipcode in a sql query that returns a recordset of all candidates for that district.
3. Use cfmail to send an email to all those candidates with one click.

I'm naturally using URL variables to pass the street address to a results page now. How do I turn that zip code result into another variable that I can use in a sql query? Would I make it another URL variable and pass it to another page? That'd be ok, but how can I do that without requiring the user to click another button?

I've got an idea of where to go from there, though there's probably a more elegant way. I was just gonna set those returned email addys as variables, and use them in a hidden form field of the form with the sample email message. Users can alter that as they wish, and when they click "submit" all that stuff will pass as URL variables to the "thank you" page which will run the cfmail and send the message to those addresses.

What do you think?

Thanks again for any suggestions...
Joe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2008 Oct 07, 2008
<cfset zipCode =
replace(addressObj["ResultSet"]["Result"]["Zip"].XmlText, '-', '', 'all')>

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2008 Oct 07, 2008
how's this for a logic flow:

user enters an address into the form field and submits the form.

the form;s action page looks up the zip code for the submitted address,
and if, found, looks up all candidates in your db based on that zip.
you either output 'sorry, no zip/candidates found' or a form with a
textarea to enter/edit the message to be sent. in a hidden field in the
form store the list of candidate ids retrieved from your db.

the user edits the message text and submits the form.

you use the candidate ids from the form;s hidden field to lookup their
emails and send them the user's message using cfmail.

you can substitute session var for the hidden form field if you want to.
you can even just store the retrieved zip code in the session var/hidden
form fields instead of candidates' ids and just do another db lookup for
candidates' emails based on the zip code after the user submits the
message to be sent.

form variables (field values) are accessed on the action page using
#form.fieldname#. i suggest you stick to form variables instead of url
variables (use method=post instead of get in your forms).

hth

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2008 Oct 07, 2008
LATEST
Thank you sir. You guys are great!

That's close to what I was thinking, but you've simplified a step. I'll probably be back with more questions on the details, but I think I can get most of the way there.

Thanks again!
Joe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources