Twitter: raymondcamden


Address: Lafayette, LA, USA

Google Geocode CFC

01-26-2007 8,803 views ColdFusion 41 Comments

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.)

41 Comments

  • Commented on 01-26-2007 at 4:58 PM
    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.
  • Commented on 01-26-2007 at 6:01 PM
    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.
  • Commented on 01-26-2007 at 6:08 PM
    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.
  • Commented on 01-26-2007 at 6:55 PM
    John: Heh, I swear I'm not stealing. :)

    Charlie: Dude - who needs docs? ;)
  • Commented on 01-26-2007 at 7:05 PM
    Hehe I know but hey like we talked about before I'm learning and trying to contribute to the ColdFusion community.
  • Josen Ruiseco #
    Commented on 01-26-2007 at 7:09 PM
    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
  • Commented on 01-26-2007 at 10:59 PM
    Thanks Josen. Should be fixed now.
  • Lola LB #
    Commented on 01-27-2007 at 5:56 AM
    This code is really cool - thanks for creating it!
  • Commented on 01-27-2007 at 11:17 AM
    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.
  • Commented on 01-28-2007 at 9:27 AM
    Ray, that's really cool! Thanks for sharing, and thank your client!
  • Jeff Gladnick #
    Commented on 01-28-2007 at 8:39 PM
    John Blayter also added this functionality to CFgooglemap, 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/
  • Commented on 01-29-2007 at 8:32 AM
    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.
  • Brian #
    Commented on 01-29-2007 at 9:10 AM
    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...
  • Commented on 01-29-2007 at 9:16 AM
    Brian, as far as I can see the API does not allow for that.
  • Jean-Michel #
    Commented on 01-29-2007 at 11:15 AM
    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."
  • Jean-Michel #
    Commented on 01-29-2007 at 11:16 AM
    forgot to enter the address sorry
    rue des m├ęsanges bleues, belgium
  • Commented on 01-29-2007 at 12:48 PM
    I had forgot to refresh the cache. It works.
  • Jeff Gladnick #
    Commented on 01-29-2007 at 1:53 PM
    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 cfgooglemap 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)
  • Commented on 01-29-2007 at 5:05 PM
    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.
  • Commented on 02-26-2007 at 3:45 PM
    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
  • Commented on 02-26-2007 at 4:12 PM
    Try redownloading from RIAForge please.
  • Greg #
    Commented on 03-18-2007 at 11:47 PM
    Hi Ray,

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

    Thanks,

    Greg
  • Commented on 03-19-2007 at 7:02 AM
    Just switch to cfinvoke syntax. That should work.
  • Andreas #
    Commented on 12-30-2007 at 5:29 AM
    I just tried it with CF MX 6.1 but here it doesn't work. Any hint for me?
  • Commented on 12-30-2007 at 9:07 AM
    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.
  • Commented on 10-09-2008 at 2:47 PM
    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.
  • Commented on 10-09-2008 at 2:57 PM
    Warning - I'm a beer snob. ;)
  • Commented on 10-09-2008 at 4:40 PM
    Are we talking something like Chimay beer?
  • Commented on 10-09-2008 at 8:37 PM
    Never heard of it - which means I'd love to try it. :) Shoot, even a bad beer, if new, is fun to try.
  • KJ #
    Commented on 02-18-2009 at 11:47 PM
    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
  • Laker #
    Commented on 03-02-2009 at 4:37 PM
    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
  • Commented on 03-02-2009 at 4:39 PM
    Mainly to support CF7. JSON wasn't native till CF8.
  • Commented on 05-07-2009 at 10:21 PM
    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!
  • Commented on 05-08-2009 at 6:01 AM
    No problem. Glad it was useful!
  • Commented on 12-07-2009 at 12:08 PM
    Hi Raymond,
    Looks like Google has changed something in their API. The demo is now returning an error

    "Element ADDRESSDETAILS.COUNTRY.COUNTRYNAMECODE.XMLTEXT is undefined in XMLRESULT."
  • Commented on 12-07-2009 at 12:40 PM
    Care to attempt a fix? ;) May be quicker than I get to it.
  • Commented on 12-08-2009 at 12:23 PM
    I just tested and it worked fine. Please tell me what you used for an input.
  • Commented on 03-03-2010 at 10:52 PM
    Hey Ray, Great work! Wondering what happens when someone puts in a partial address. any way to get suggestions, much like the "Did you mean?" on the Google maps pages?
  • Commented on 03-04-2010 at 6:18 AM
    As far as I can read, Google does not provide for this. It can work with slightly incorrect addresses and try to "do the right thing", but it won't specifically say, "This was wrong, did you mean X" instead.
  • Commented on 07-01-2010 at 1:49 PM
    Is the project no longer available? I tried going to http://googlegeocode.riaforge.org/ and it just redirects to the homepage. Searching for the project yields no results.

    I am hitting the same error with the Country. Attribute [COUNTRY] not found in XML Node (org.apache.xerces.dom.DeferredElementNSImpl)

    It seems that google dropped the country substruct and just has COUNTRYNAMECODE.
  • Commented on 07-01-2010 at 5:09 PM
    Use this now:

    http://googlegeocoder3.riaforge.org/

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty