refactor google geocoding
ray007 - March 30, 2007 - 18:21
| Project: | location (API, module) |
| Version: | 5.x-1.x-dev |
| Component: | Data update |
| Category: | task |
| Priority: | normal |
| Assigned: | ankur |
| Status: | active |
Description
Is there a reason that (in the absence of other working service-providers) google maps call isn't used as fallback for _all_ addresses worldwide?
I know it does work for germany and austria ... no use to write the same function over and over again for all countries.
In the presence of the gmap module we could even reuse the apikey used there.
If there's no reason, I can come up with a patch to make it so ;-)

#1
Since there were no replies I decided to go a slightly different route for now.
The attached patch
- introduces a new file
supported/geocode_google.inc- defines function
location_geocode_google()andlocation_geocode_google_settings($cc = NULL)in there- calls those 2 function for the specific function for 'us' and 'ca'
- adds similar code to provide geocoding and maplink with google for countries 'at' and 'de'
I think we need to define a "global service provider" that can be referenced from several countries, but this solution is good enough for me for now.
Comments?
#2
changed status and renamed issue to more proper title
#3
Is there anything wrong with my patch?
I had been hoping for some feedback ...
#4
+1 for this. Gmaps is by far the most widely adopted mapping and geocoding service outside of the US...I believe pretty much all of Europe and certainly Australia are included...not sure about Asia.
#5
You can add 'nl' to the list of countries which can be geocoded by google.
#6
+1 AFAIK google maps is currently the best option. It makes sense to run with this until a better service appears, and then switch over to that one! Internationalisation of location.API is long overdue. Nice one Ray :)
#7
is there anything I can do for this patch to be considered for inclusion?
#8
There are limitations with just using google, so maybe finding a clean way to allow for failovers would be good too. I write about the shortcomings of using just any one service over here - http://www.developmentseed.org/blog/geocoding/geonames
Ian
#9
I do not doubt that a solution allowing the use of arbitrary geocoding-services would be preferable, but
- google seems to work for most situations where there's nothing working out of the box now
- i have a patch making it work with google right now
those of you living in the usa or canada may not feel the lack of a solution covering the rest of the world, but the rest of the world does ...
#10
Ray, it seems that your patch is exactly what I needed, but for France (I was looking here before: http://drupal.org/node/147037).
How should I proceed to implement your patch? Does it work like this? Or do I have to replace "de" for Germany, by "fr" for France for example in your patch?
Thank you anyway for the job!
#11
copy one of the country include files to location.fr.inc and change everything in the file that looks like the country code to 'fr'. remove the province list (if there is one) or write one for france and chances are pretty good it will work then ;-)
#12
What I did:
- applied your patch, which created a "geocode_google.inc" file that I copied to the "modules/location/supported/" directory.
- already had a "location.fr.inc" file in that directory
What do I need to do next to get geocoding working ?
#13
look at the file
location.at.incYou will probably copy over and adapt to country code 'fr' the following functions:
- location_map_link_*
- location_geocode_*
don't forget to
require_once('geocode_google.inc');and see what happens ;-)#14
It works with Spain but not the proximity searches.
Any suggestions? Does proximity search work with other countries (at, fr, de, nl)?
#15
Ray, I done what you said ;)
Now I have the following error message at the top of the submit form when trying to add a location enabled event:
Would you have time to look at them, I attach:
- geocode_google.inc (I added "txt", uploading "inc" files is not allowed), since I am not sure to have performed the patch correctly
- location.fr.inc. (in the next comment)
Thank you anyway for your instructions.
#16
and here is "location.fr.inc"
#17
your location.fr.inc file seems completely broken.
re-create it again starting from location.at.inc (or one of this others using google_geocode.inc)
#18
I applied the patch from my PC (windows) and uploaded the results to my host. For some reason, patching from my PC didn't work properly (although I used Unxutils as explained here : http://drupal.org/node/60179).
Then I tried to apply the patch directly from my host, using Putty. And it worked !
So thank you very much for your help Ray!
Just one question now: is there a way to display the map associated with the node instead of a "See map: Google Maps" link (the map is only displayed in the node for addresses in the US)?
#19
I have work in progress on a gmap cck field (see http://drupal.org/project/gmap_addons) and location-integration is on my list of things to do ... but will take some time.
#20
Hello Im french Bob Louis.
And I would like to do the same thing like you. I can not geocode mi adresses?
What should I do?
Thanks a lot
#21
Only just spotted this thread.
I wrote a patch a while back which makes use of the Geonames service as a fallback:
http://drupal.org/node/75459#comment-216146
It seems to work pretty well for me for most countries (although with more accuracy in some than others...)
It could be adapted to also use Google Maps where geonames doesn't provide a suitable response, or vice-versa.
Tim
#22
@obscurity:
Yes, I've already seen this thread.
As I already wrote in another comment, I think we need to introduce the concept of "global geocoding services", and those have a list of countries they support. But until we get word from the maintainers about what changes they'd accept I'll happily live with using google for the countries I need. Seems to work well enough so far.
#23
I've actually been looking at the patches on this thread over the last month or so and been using them to write something similar. I should have something similar up soon (i.e., within the next week or two).
-Ankur
#24
Hey Ray!!
Your patch looks unbelievably awesome. But I have a problem, a severe handicap. I am a noob!!! I cant seem to figure out how to patch or implement the patch.
Someone please help!!!
Cheers
Nash
#25
After much internal debate, and the admission to not knowing any php (limited php rather) i decided to look at the code for my self.
Well I took the us file and restructured it for nz. It works. The geocoding i mean but thats as far as it gets. I cant seem to get google maps to get the location information and display a map in the node. Maybe i need to understand the google maps module better. On the other hand i got it to work with the see map links module. (which means it opens in a new page and at the google website).
I would be eager to get some help re displaying a map within the node that gets map data from location module.
Cheers
Nash
Ps: if anyone requires the code for customising location to geocode your location contact me and i will fill you in. Basically what is to consider is does maps.google.com know where you are? Yes? then it will work. Oh! and i got my locations module to work for New Zealand
#26
I've committed a fix for this issue. Google geocoding now takes place in only one function and you only have to enter a Google API key once. I will also look into adding additional countries for which Google Maps has recently begun offering geocoding web services. ray007 and BobLouis, thanks for your patches.
-Ankur
#27
#28
Hi, I'm sorry to reopen this issue but I'm slightly confused about its status. I tried using the file at the top of this page but it doesn't seem to provide any geocode details for uk data.
#29
SUbscribing. I have the same behaviour as stated for uk data. But for me it is Spanish dat which is not provided.
Greetings,
Martijn
#30
Subscribing, I have the same issue as #28 for UK addresses
#31
Changing component to Data update.
#32
Whole bunch of geocoding issues marked as duplicate of this one: http://drupal.org/node/66887
#33
subscribing. We do essentially this with a bespoke patch for www.folkjam.org and would really like to have a google geocode fallback for all locations.