I have been scratching my head, trying various configurations, and reading forum posts for days, trying to get geocoding to work for node locations with Gmap. I have tried disabling geocoding in the location module, and enabling the Google geocoder in GMap Location, and the reverse. I've tried it with both enabled, I've tried configuring the map linking and geocoding tabs in the location module (per http://drupal.org/node/147037). Nothing seems to work. My maps are displaying, and I can get a marker by entering lat/long or by clicking on the map, but no geocoding from the location address.
There seems to be lots of discussion around geocoding, and several geocoding module projects, and I noticed in the CSV messages that the latest release had updated address.js functionality, etc...
The GMap UI indicates that geocoding is possible, but the documentation is unclear and there are lots of other signals that maybe it doesn't work. Can someone clarify this for me, and if it does work, point me in a direction to get it working on my site.
Any help would be greatly appreciated.
-David
Comment | File | Size | Author |
---|---|---|---|
#32 | geocode_update.tar_.gz | 1.65 KB | EvanDonovan |
Comments
Comment #1
ray007 CreditAttribution: ray007 commentedI think geocoding is the task of the location-module. Gmap is for picking a location interactively on a map.
For US and canada, server-side geocoding should work with location module out of the box, other countries need patches for country-support.
Comment #2
boaz_r CreditAttribution: boaz_r commentedI'm actually reading this to gather the same information. But I can add the following:
- See http://www.google.com/apis/maps/documentation/index.html#Geocoding_Examples for examples on how to do geocoding directly via google. The code I maintain, in specific, uses the following HTTP approach (in PHP):
- I am looking to move it to some function, rather working directly against Google.
- I agree that the documentation is lacking. I'm pretty sure there are nowadays stable enough functions in either gmap and/or location modules, or at least I hope. I'm keeping looking. If you're desperate, you can use the above code. How? In many ways. For example, utilizing nodeapi() hook in the appropriate "ops".
Comment #3
ray007 CreditAttribution: ray007 commentedThere already is some support to use the google api for geocoding in the location module.
Ankur said he's currently working on improving the current situation, see also http://drupal.org/node/132541
Comment #4
daboyd CreditAttribution: daboyd commentedThanks Ray, Just to clarify -if I install your patch from http://drupal.org/node/132541, node address (location) information will be used to automatically geocode using google? So, I should not expect this to be the case "out of the box" with just the location, gmap and gmap_location modules installed? Even though the location UI for node edit seems to indicate that this is the case?
Just to re-state my issue. Everything works as expected except for geocoding.
-David
Comment #5
ray007 CreditAttribution: ray007 commentedIf you're living in the usa or canada, it should work. Otherwise you'll probably want to use my patch and maybe update your country include file by looking at the austrian (at) or german (de) one. I've seen somewhere a patch for uk, no idea about other countries.
Comment #6
daboyd CreditAttribution: daboyd commentedRay -to clarify, "If you are living in the usa or canada it should work" means that it should work "out of the box" or it should work with the patch? I'm afraid that I am still a bit confused on this point. I actually need to have it work globally if possible, so I suspect that the patch will be useful either way. I'm just trying to get a clear picture of what works and what doesn't.
Also see James' (the former gmap maintainer) comment to this parallel thread http://groups.drupal.org/node/5083#comment-15348, which indicates that there is an incompatibility between gmap_location.module and location.module.
Comment #7
nashINATOR CreditAttribution: nashINATOR commentedHi there,
i face a similar problem only slightly different.
I finally got the location module to geocode for me through the google website but i cant seem to get a map to display on the node. Correct me if i am wrong. I installed the google map cck to do this but it does not seem to take any information from the location module. How do i get this to work? Help anyone?
Btw. I got location to geocode for me by ading a bit of code to the location.nz.inc (I live in New Zealand) I actually copied it from the location.us.inc file and deleted all functions except the ones that connected to the google site.
attached below is that code. You can modify it so that where it says "nz" change it to the initials of your country.
Comment #8
ray007 CreditAttribution: ray007 commented@daboyd:
There currently is no glocal geocoding in the location module. But I hope ankur is working on that. Gmap clientside javascript geocoder could probably do that too, but I haven't yet used it. And I don't think it would be problematic with location's geocoding, since I think location doesn't try to geocode if there are user-provided coordinates.
@nashINATOR:
The gmap-cck field doesn't yet have location integration.
You either need to show the map with some php code, or you can use a gmap-view.
Comment #9
tom_o_t CreditAttribution: tom_o_t commented@nashINATOR
Thanks for that demonstration of how to add geocoding for new countries - I hadn't realised it was that straightforward!
As another simple alternative to Ray007s suggestions for displaying the map, you can just enable the "location map" block for the appropriate content type that you created with CCK - just set it to display in the 'content' region. Under the configuration menu you can enter a Macro to set the zoom level, width, height, etc.
Comment #10
daboyd CreditAttribution: daboyd commentedI have now resolved my original problem. The location module will geocode based on the node location information, at least for the US (I have not yet tried outside of US). It turns out that one needs to enter the google API key in two locations: gmap module settings (admin => module settings => gmap), and location module settings (admin => module settings => location => geocoding options tab => configure parameters). In retrospect this makes complete sense as the location module is doing the geocoding and the google API key would be required to call google's geocoder. However, the UI is not at all intuitive as the "configure parameters" link appears to only apply to Yahoo. If anyone working on location.module is listening, a lot of grief could be saved by fixing this.
Thanks to boazry for this post that cleared up the matter for several of us http://groups.drupal.org/node/5083#comment-15439. From my perspective, the issue is now resolved. Thanks to everyone who responded!! -David
Comment #11
dwees CreditAttribution: dwees commentedI used the snippet below to update all of my user's (node) profiles with the proper latitude and longitude (at least in those countries where Geocoding is supported by Google).
Comment #12
Summit CreditAttribution: Summit commentedSubscribing. Looking forward to global geocoding because with my website I need to be able to set nodes all over the world!
greetings,
Martijn
Comment #13
dwees CreditAttribution: dwees commentedIt looks like Yahoo! provides a good service for this. Not precisely sure exactly how to modify my code (I don't have their API in front of me) but I do know they will provide Geocoding for all (almost all?) of the major cities in the world, but not street level accuracy.
Dave
Comment #14
kobnim CreditAttribution: kobnim commentedsubscribing
Comment #15
Rick Hood CreditAttribution: Rick Hood commented@daboyd #10
Wow thanks for this - I was going crazy trying to figure that out. And this was stumping me too "However, the UI is not at all intuitive as the "configure parameters" link appears to only apply to Yahoo."
Comment #16
timflan CreditAttribution: timflan commentedResponding to @daboyd #10
THANK YOU! I was going just about bonkers with this same ridiculous problem. And I promise you I would NEVER have discovered the SECOND spot for the Google Maps API: location module settings (admin => module settings => location => geocoding options tab => configure parameters).
Comment #17
EvanDonovan CreditAttribution: EvanDonovan commentedHere's a little code snippet I wrote based on #11 to update nodes' geocodes using the google_geocode_location() function provided by the location module. I've tested it up to 75 rows at a time, but it may still have bugs or run slower than it ought to. Let me know if there's an easier way to do this.
Note that for this script to work, you will have had to enable the Google geocoder for the countries in which you have location data and have put the Google Maps API key in the settings for the Location module, as described earlier in this thread.
UPDATED 7/28:
Comment #18
mroswell CreditAttribution: mroswell commentedsubscribing
Comment #19
techutopia CreditAttribution: techutopia commentedHi,
I have changed a little of the code in #17 and produced something that works similarly, but provides some output for feedback on Geocode updates.
The resultant output is tabular:
Nid, Eid, Lat, Lon, Status, link
1539, 3499, 49.264601, -124.788480, RESULT*, link
1538, 3498, 50.754050, -119.228004, RESULT*, link
* - RESULT is currently of 3 types:
PRESENT - Node Geocode data is already present
FAILED - Could not get Geocode from Google - usually because of a bad address
FETCHED - Geocode data fetched from Google successfully
Obviously the 'link' column is a link to the node concerned so any bad addresses can be investigated.
I have also added a 'delay' into the code after a query is made to Google (currently a 1 second delay).
I did this as I found that Google throttles requests and too many requests sent quickly will result in data not being returned occasionally.
Code works well for me, would it be useful to others?
Comment #20
mroswell CreditAttribution: mroswell commentedSure!
Comment #21
EvanDonovan CreditAttribution: EvanDonovan commentedI'd love to see your updated version of my code. Could you post it on here as an attachment?
Thanks!
I didn't realize Google throttled requests; maybe that caused some of my data not to update...
Comment #22
dwees CreditAttribution: dwees commentedI think the limit is 50,000 queries per hour or something similarly high. Should check the FAQ page for the developers of the Gmaps, I'm sure it's there.
Dave
Comment #23
techutopia CreditAttribution: techutopia commentedAs per my #17 post, here's the code.
Note: This is my 1st bit of drupal PHP code, so the usual caveats apply. ;-)
Comment #24
EvanDonovan CreditAttribution: EvanDonovan commentedI like the table output, for debugging purposes. On a brief review, I would say that the MySQL query you've added in shouldn't be necessary, since the node_load call has already loaded $node->location as an object. After the line in which I set
$location = $node->location
, you should be able to do something like the following:In any case, Drupal's database abstraction layer eliminates the need for any direct MySQL calls.
Thanks for the code! I'll use a modified version of it from now on.
Btw, I wasn't only doing the lat/lon query from Google when lat/lon was currently NULL, since we had values in the table already, just not accurate ones. You can either add the conditional or leave it out, as necessary for your needs.
Comment #25
computer_jin CreditAttribution: computer_jin commentedHi dwees ,
I am using this code to get longitude and latitude but i am receiving an empty result. can u please tell me how can i solve this .....?
Comment #26
dwees CreditAttribution: dwees commentedOne possibility is that the API has changed. This code is over a year old, the Geocoding API may have changed since then. I certainly haven't used this recently.
Dave
Comment #27
EvanDonovan CreditAttribution: EvanDonovan commentedcomputer_jin, et al.: Here's an updated version of the script for the 6.x version of the Location module.
There were some API changes in both Location and Drupal that I had to make. I also added usleep to keep from throttling the Google geocoder, and made the script faster, I believe, by replacing the node_load with a more optimized query.
Finally, I changed the script to only update locations where latitude & longitude were 0,0 or 180, 360. So you would have to change my $location_sql query if you wanted it to update all locations (even those that currently had latitude & longitude values), like the old script did.
Let me know if this works for you.
Comment #28
EvanDonovan CreditAttribution: EvanDonovan commentedBy the way, I'm thinking of turning something similar to this script into an operation for use with admin/content/node and the Views Bulk Operations module. Would anyone have interest in that?
Comment #29
Summit CreditAttribution: Summit commentedHi,
It would be great if this would become a submodule of location to batch add lat/lon to geographical data like country, province, city...
Would anyone be willing to build this module using above snippets?
greetings, Martijn
Comment #30
EvanDonovan CreditAttribution: EvanDonovan commented@Summit: I actually have a module that does this. It's a slightly modified version of the code from #27. It's not incredibly well-tested, but it's been working on my site for quite some time. If you would like it, I will post it in this issue (as a tar.gz). I don't know whether I would be willing to actually become the maintainer of it though.
Comment #31
Summit CreditAttribution: Summit commentedHi great to post this module als tar. then, yes please. See what's coming from that !
Thanks a lot in advance.
greetings, Martijn
Comment #32
EvanDonovan CreditAttribution: EvanDonovan commentedHere you go. Let me know if it works for you. If you really think it's useful, I might consider making it a module on Drupal.org - but I'd have to learn CVS first.
After you have a chance for feedback, I think I'm going to close this issue, since it's wandered quite far from the original post topic.
Comment #33
alfarovive CreditAttribution: alfarovive commentedEvanDonovan:
Would this work with a location cck rather than the nodes location?
Thanks
Comment #34
EvanDonovan CreditAttribution: EvanDonovan commented@alfarovive: If those use the same location tables to store latitude & longitude, yes. I'm not sure; I've never used them.
Comment #35
Summit CreditAttribution: Summit commentedHi, No CCK Location uses different tables to store latitude & longtitude. Greetings, Martijn
Comment #36
EvanDonovan CreditAttribution: EvanDonovan commentedThen I guess the code would have to be modified. Sorry I don't have time at the moment.
Comment #37
rooby CreditAttribution: rooby commentedThis is a location module issue
Comment #38
heshanlksub
Comment #39
EvanDonovan CreditAttribution: EvanDonovan commentedHmm...I should probably make #32 into a contrib module at some point. I have a CVS account now, so it would be easier. Note to self to do that, but I don't have time right now.
Comment #40
EvanDonovan CreditAttribution: EvanDonovan commentedUnder most circumstances I think that the instructions on http://drupal.org/node/1041632 should be sufficient for mass geocoding of node locations. I added a link at the bottom of that page to the sandbox project I created in #32, which still works to my knowledge, though would need to be edited for CCK Locations.
I am going to mark this as "fixed" since this should not be handled, I believe, by the core Location module, but would be the task of a separate contrib module. I don't have the time or resources presently to work further on this however.