Google Geocode CFC

So - I have a real cool client. This client had a request for code that would integrate with Google's Geocode API. This same client also had no problem with me making a nice CFC out of the code and sharing it with the world. This client wants to remain anonymous, but he has my thanks.

You can download the CFC here: http://googlegeocode.riaforge.org/.

I also created a simple demo.

Enjoy.

Oh - and if you were using RIAForge today and noticed some downtime - sorry. I've been trying to get a system update all week and I finally got it finished today. (Yes, I did a major system update at 3PM on a Friday and yes, I know how dumb that is.)

Comments

John Ramon's Gravatar See Ray once again your making me look bad, hehe not really but thanks for showing this I posted this a couple of weeks ago on geocodeing addresses. http://www.johnramon.com/index.cfm/dopost/yes/id/7...

Yea it's not as pretty as your but hey I'm trying.

Keep up the good work.
# Posted By John Ramon | 1/26/07 4:58 PM
Charlie Arehart's Gravatar Very nice, Ray. Thanks (to you and the client) for sharing it.

For any who see this and are unfamiliar with APIs like Google's, you will need to obtain a key from them before you can run this code locally. Ray's online demo must be using his (or his client's) key.

To get a new key, and indeed to learn more about the API, note the links on the top left of the page Ray points to.

I was impressed to see that one gets 50,000 requests per day. That's very generous. I see also that if you use this for a non-public site, then you are expected to get an enterprise license. Just trying to foresee some questions that others might have (and indeed that I had) on seeing this nifty demo.

Great stuff as always, Ray.
# Posted By Charlie Arehart | 1/26/07 6:01 PM
Terrence Ryan's Gravatar That's so cool. It makes me want to write something just to have a need for it.

Ooooh Actually I have a thought right now.
# Posted By Terrence Ryan | 1/26/07 6:08 PM
Raymond Camden's Gravatar John: Heh, I swear I'm not stealing. :)

Charlie: Dude - who needs docs? ;)
# Posted By Raymond Camden | 1/26/07 6:55 PM
John Ramon's Gravatar Hehe I know but hey like we talked about before I'm learning and trying to contribute to the ColdFusion community.
# Posted By John Ramon | 1/26/07 7:05 PM
Josen Ruiseco's Gravatar Got an error when entering my rural address. Apparently the code breaks when Google doesn't have responses available for all fields.

Entered: 33521 S. State Rt. F, Garden City, MO 64747

Error:

Element ADDRESSDETAILS.COUNTRY.ADMINISTRATIVEAREA.SUBADMINISTRATIVEAREA.LOCALITY.LOCALITYNAME.XMLTEXT is undefined in XMLRESULT
# Posted By Josen Ruiseco | 1/26/07 7:09 PM
Raymond Camden's Gravatar Thanks Josen. Should be fixed now.
# Posted By Raymond Camden | 1/26/07 10:59 PM
Lola LB's Gravatar This code is really cool - thanks for creating it!
# Posted By Lola LB | 1/27/07 5:56 AM
doug's Gravatar Ray,
Thanks, I often have to geocode customers who have moved since the last USPS, MS Mappoint, and Marketing db updates. I have been using Google Earth for the task, but this is so much faster and lean than having to fire up Google Earth.
D.
# Posted By doug | 1/27/07 11:17 AM
Rick Root's Gravatar Ray, that's really cool! Thanks for sharing, and thank your client!
# Posted By Rick Root | 1/28/07 9:27 AM
Jeff Gladnick's Gravatar John Blayter also added this functionality to CF_googlemap, which is hands down the best way to do google-mapping in a CF environment.

Check it out:
http://www.blayter.com/john/cf_googlemap/
# Posted By Jeff Gladnick | 1/28/07 8:39 PM
Phillip Senn's Gravatar Ray,

Competition is a good thing, and collaboration is a good thing.
Since John has posted his project on RIAForge as well, would you consider becoming a contributor to his project? I think it would legitimize the need for a GoogleMaps cfcomponent and add a developer to your team.
# Posted By Phillip Senn | 1/29/07 8:32 AM
Brian's Gravatar When you retrieve results, are you giving a pick option that you bias? Here's why I ask... The address I entered was 203 W Losey St, Scott AFB, IL, 62225

The returned address was on East Losey Street

Using the google maps interface (in times past) I've been asked for clarification between east and west Losey...Today when I checked, it took me right to W Losey.

hmmm...
# Posted By Brian | 1/29/07 9:10 AM
Raymond Camden's Gravatar Brian, as far as I can see the API does not allow for that.
# Posted By Raymond Camden | 1/29/07 9:16 AM
Jean-Michel's Gravatar Cool, it works for brussels Belgium but... throws an error for my (not so) rural address (with european characters I admit)
"Element ADDRESSDETAILS.COUNTRY.ADMINISTRATIVEAREA.SUBADMINISTRATIVEAREA.LOCALITY.THOROUGHFARE.THOROUGHFARENAME.XMLTEXT is undefined in XMLRESULT."
# Posted By Jean-Michel | 1/29/07 11:15 AM
Jean-Michel's Gravatar forgot to enter the address sorry
rue des mésanges bleues, belgium
# Posted By Jean-Michel | 1/29/07 11:16 AM
Raymond Camden's Gravatar I had forgot to refresh the cache. It works.
# Posted By Raymond Camden | 1/29/07 12:48 PM
Jeff Gladnick's Gravatar I'm not aware of being able to ask for clarification, but you can dumb down the geocode call until it works. Thats how we do it at work, and how cf_googlemap works.

You setup the the function to recursively call itself, and use a weaker attempt at an address each time. For example
1st call: Street1 Street2 City State Zip, State, Country
if fail
2nd call:Street1 City State Zip, State, Country
if fail
3rd call:Street1 City State Zip, Country
if fail:
4th call: Street1 City State, Country
if fail:
5th call: Street1 City State, Country
etc, etc, etc

Thats how it works in cf_googlemap. Ray, i fully encourage you to help out with cf_googlemap (if you have time, you are already carrying a lot of weight as it is)
# Posted By Jeff Gladnick | 1/29/07 1:53 PM
Raymond Camden's Gravatar I'll leave it up to John. John - do you think my handling of this function is better? If so I'm cool with you rolling in mine and I'll disable my project.
# Posted By Raymond Camden | 1/29/07 5:05 PM
Randy Taylor's Gravatar Thanks for posting this CFC it's exactly what I need for a project. I setup a test and am getting an error. If you get a chance go to http://www.taylordc.com/test.cfm and enter the following address:

"27882 Via Del Agua, Laguna Niguel, CA 92677"

I get "Element ADDRESSDETAILS.COUNTRY.ADMINISTRATIVEAREA.SUBADMINISTRATIVEAREA.LOCALITY.LOCALITYNAME.XMLTEXT is undefined in XMLRESULT."

I'm running this on CF7 and not sure what would cause this since if I go to the demo at http://ray.camdenfamily.com/demos/googlegeocode/te... it works and if I go to http://maps.google.com it works as well.

Any help is much appreciated!

Thanks,
Randy
# Posted By Randy Taylor | 2/26/07 3:45 PM
Raymond Camden's Gravatar Try redownloading from RIAForge please.
# Posted By Raymond Camden | 2/26/07 4:12 PM
Greg's Gravatar Hi Ray,

Could you provide us with some code samples for this project that will work with GoDaddy hosting(createObject disabled)?

Thanks,

Greg
# Posted By Greg | 3/18/07 11:47 PM
Raymond Camden's Gravatar Just switch to cfinvoke syntax. That should work.
# Posted By Raymond Camden | 3/19/07 7:02 AM
Andreas's Gravatar I just tried it with CF MX 6.1 but here it doesn't work. Any hint for me?
# Posted By Andreas | 12/30/07 5:29 AM
Raymond Camden's Gravatar Well, it says on the RIAForge page that CF7 is required. So that should be obvious. I believe the only CF7 code is the use of result in the cfhttp tags. You could remove that and use the cfhttp variable instead.
# Posted By Raymond Camden | 12/30/07 9:07 AM
Dave Dugdale's Gravatar I just used your CFC, works great. I was using a Yahoo map API but that starting failing this week. Thanks! If I ever meet you I would like to buy you a beer.
# Posted By Dave Dugdale | 10/9/08 2:47 PM
Raymond Camden's Gravatar Warning - I'm a beer snob. ;)
# Posted By Raymond Camden | 10/9/08 2:57 PM
Dave Dugdale's Gravatar Are we talking something like Chimay beer?
# Posted By Dave Dugdale | 10/9/08 4:40 PM
Raymond Camden's Gravatar Never heard of it - which means I'd love to try it. :) Shoot, even a bad beer, if new, is fun to try.
# Posted By Raymond Camden | 10/9/08 8:37 PM
KJ's Gravatar I want to do query on addresses and display on google earth on sepate winow when user click button show map. on click data should show on google earth.

I created kml file and had href link with kml file <a href=addresses.kml> sgoe map</a> When user clicks the link the kml displays on the page not the map.

Thanks
# Posted By KJ | 2/18/09 11:47 PM
Laker's Gravatar Just curious... was the choice to XML return data (versus JSON, for example) arbitrary, or was there a specific reason? Parsing speed or some-such... seems like JSON would be lighter weight, but I'm speculating. I made mod the CFC a bit and see what happens...

BTW, your timing was perfect. I'm just starting a project I've been putting off that needs the functionality your component provides.

Thanks,
Laker
# Posted By Laker | 3/2/09 4:37 PM
Raymond Camden's Gravatar Mainly to support CF7. JSON wasn't native till CF8.
# Posted By Raymond Camden | 3/2/09 4:39 PM
Bob Silverberg's Gravatar Hey Ray, I just used your component in a fun little side project in which I created a Google Map of all of a user's friends from Twitter. It was great to be able to use RIAForge to find both a Twitter API wrapper and this Google Geocode wrapper. Thanks!
# Posted By Bob Silverberg | 5/7/09 10:21 PM
Raymond Camden's Gravatar No problem. Glad it was useful!
# Posted By Raymond Camden | 5/8/09 6:01 AM