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.)
Archived Comments
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/in...
Yea it's not as pretty as your but hey I'm trying.
Keep up the good work.
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.
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.
John: Heh, I swear I'm not stealing. :)
Charlie: Dude - who needs docs? ;)
Hehe I know but hey like we talked about before I'm learning and trying to contribute to the ColdFusion community.
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
Thanks Josen. Should be fixed now.
This code is really cool - thanks for creating it!
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.
Ray, that's really cool! Thanks for sharing, and thank your client!
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...
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.
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...
Brian, as far as I can see the API does not allow for that.
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."
forgot to enter the address sorry
rue des mésanges bleues, belgium
I had forgot to refresh the cache. It works.
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)
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.
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/tes... 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... it works and if I go to http://maps.google.com it works as well.
Any help is much appreciated!
Thanks,
Randy
Try redownloading from RIAForge please.
Hi Ray,
Could you provide us with some code samples for this project that will work with GoDaddy hosting(createObject disabled)?
Thanks,
Greg
Just switch to cfinvoke syntax. That should work.
I just tried it with CF MX 6.1 but here it doesn't work. Any hint for me?
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.
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.
Warning - I'm a beer snob. ;)
Are we talking something like Chimay beer?
Never heard of it - which means I'd love to try it. :) Shoot, even a bad beer, if new, is fun to try.
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
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
Mainly to support CF7. JSON wasn't native till CF8.
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!
No problem. Glad it was useful!
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."
Care to attempt a fix? ;) May be quicker than I get to it.
I just tested and it worked fine. Please tell me what you used for an input.
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?
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.
Is the project no longer available? I tried going to http://googlegeocode.riafor... 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.
Use this now:
http://googlegeocoder3.riaf...