Hi,
I am cross-posting this with the support forum (http://drupal.org/node/158052) as I didn't get an answer there. If anyone can point me in the right direction, or at least let me know if geocoding node locations is possible I'd be greatly appriciative.
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. Nothing seems to work. From reading posts here and in the development forums, I see that there is activity around building at least 2 geocoding modules.
The GMap UI seems to indicate that geocoding is possible, but the documentation is unclear and there are lots of other signals that 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.
Thanks! -David

Comments
The stuff below should help
The stuff below should help you to build a map -> click -> co-ords -> DB interface, if this is any good to you.
I chatted with bdragon (gmap maintainer) on this yesterday, I got some info but I've not had time to look into it at all yet. To be perfectly honest, I'm so confused I don't know what's going on!
This is the info I got from bdragon on the matter:
<Bdragon|work> NikLP: Cheater's way: hidden functionality in gmap_set_location
<Bdragon|work> NikLP: Correct way: gmap_widget_setup your latitude and longitude fields as 'locpick_latitude' and 'locpick_longitude'
<Bdragon|work> and your postcode field as 'locpick_address'
<Bdragon|work> and add a map with behavior flag locpick ON
crumbs... are there any docs on this? :p
<Bdragon|work> No :P
<Bdragon|work> Just look at what gmap_set_location does
ok dude, what are the steps from a fresh dev gmap to where I want to be? briefly... I will do whatever it takes to make automatic geocoding work (assuming I can bang a postcode in and the map auto updates...)
<Bdragon|work> 1) Add your fields
<Bdragon|work> 2) hook_form_alter the form
<Bdragon|work> 3) Alter in a '#type' => 'gmap' to hold the map
<Bdragon|work> 4) gmap_widget_setup($form['cck_lat_field_name'][0]['value'],'locpick_latitude','mapid');
<Bdragon|work> 5) Same for longitude and address
<Bdragon|work> The miniumum requirement of #settings on the map element is ['#settings']['behavior']['locpick'] = TRUE, and having the mapid match what you used for the third param of the gmap_widget_setup()s...
<Bdragon|work> I do something VERY similar to this in gmap_set_location() in gmap.module
This will fix a theme bug in certain themes caused by gmap:
Druplicon> http://drupal.org/node/104175 => Fieldset titles sometimes invisible in Garland => Drupal, Garland theme, normal, patch (code needs review), 3 IRC mentions
That's all I know. Other than that, you want to be looking towards the Geo.module, but that's not finished yet - this will replace Location.module AFAIK, but like I said, the situation is getting a bit confusing...! :)
Web Development in Nottingham, UK by Kineta Systems / Follow me on Twitter! @NikLP
Thanks
Thanks for the response NikLP! Being a Drupal newbie, and a marginal php hack, I am REALLY confused! Sounds like the bottom line is that automatic geocoding does not work, despite appearances in the UI. I have to say that I am a bit disappointed as this post by Michelle http://drupal.org/node/150944 seems to indicate that automatic geocoding does work. Does anyone know anything about the geocoder module that Ian Ward at Development Seed is working on http://www.developmentseed.org/blog/node/421. It looks like this might solve the problem when it is available.
I'll take a look at bdragon's instructions and see if I can make something of them. If you do figure this out yourself, any further insights (or a patch?) would be appreciated. Thanks again -David
I have some code to do a
I have some code to do a geocode lookup before submitting a node from a project a journalism grad student did for OurTahoe.org called Places. One item on my summer to-do list is to break that project up into smaller, more manageable modules. I started a project for a Geocode module, but I don't know where to put the resulting lat/long information. I was really hoping there would be more activity with the Geo module. The idea of API/schema that can be used by both basic MySQL environments as well as leverage the more advanced features of spatial databases like MySQL with spatial extensions or PostgreSQL with PostGIS is REALLY exciting.
I contacted the Development Seed folks to see if this Geocoding interface existed in any usable form. It doesn't.
Without an example app or some documentation about how the Geo module will link spatial data to nodes, I can't move forward using that. Patching Location to do the lookup before insert is an option, but that schema is limited to points. I really want to move beyond pushpins to databases capable of understand polygons and other standard spatial data types. Google has already add markup for spatial information to the sitemap.xml standard. I'd really like to see a standard location for storing spatial data that goes beyond basic lat/long and ties into the gsitemap module.
I't would be great to have
I't would be great to have an OGC-compliant geo module, and one that supported all of the functionality of the google maps API. And, just having a pushpin implementation that worked well would be a big improvement. Even though GMap is limited, if we could get the geocoding patched and some decent user documentation, the module would be much more useful to the community.
I'd be willing to help put together some improved user documentation if there are folks who are willing to fix the geocoding. Then, I'd definitely be interested in a module with the functionality that you describe. -David
It does
Location module does do geocoding when you save the node. There's a lot of settings to fiddle with so maybe you missed one. I don't have the time right now, sorry, but if I get a minute, I'll run through all my settings and see if that helps you.
Michelle
Thanks!
Thanks Michelle!
Any help you can provide would be much appreciate. The settings ARE confusing, and redundant and there is very little documentation. If I ever figure this out, I'll try to document it for everyone as I am sure there are others who are encountering the same problem. -David
My settings
Sorry to take so long. Not a lot of computer time these days. Here's what I have:
admin/settings/location
Use a Google Map to set latitude and longitude checked
admin/settings/location/maplinking
Google maps checked
admin/settings/location/geocoding
Set to Google Maps API
admin/settings/gmap_location
Enable the Google Map API geocoding: enabled
I think that covers them all. I'm going to be offline for a while so hopefully that will do it for you.
Michelle
I tried this
to no avail... I'm having similar problems as described here. When I enter a city, state or zip code (or any combination) no markers show up on the map. However, when I enter lat/lon into the location, the marker will come up on the map...
To me this indicates a problem with geocoding, and despite checking all the boxes I can and playing with this for the past 6 hours, I still can't get it........
Blah.
API key
Have you signed up for an API Key, and/or entered it correctly?
http://www.google.com/apis/maps/signup.html
Cheers,
Bill
FunnyMonkey
Tools for Teachers
FunnyMonkey
Did you save the node?
This may be a dumb question, but did you save the node? With changing lat/long, the map updates automatically. With an address, it only geocodes it when you save the node and doesn't give you any sort of warning if it wasn't able to find the address to geocode it. It's not a very good UI, unfortunately. I'd love to have a button added that you can click to run the geocoding before saving to get visible feedback but I wasn't able to figure out how to do it.
Michelle
Node saved, not working.
Hi Michelle,
Thanks for the reply. It looks like I am having the same problems as David. I've got a working Google Map API, tried every possible combination of settings, previewed the node, hit tab in the address bar, saved the node, saved the node and re edited it, upgraded to Drupal 5.1 with the most recent Gmap and Location modules, followed the Zacker video browsed every support file that was related, and still have no answer.
I think David hit the nail on the head that at one point it probably worked but with the latest releases it's stuck with some conflicts somewhere.... though maybe we're overlooking something simple.
If anyone has a site working where an address is automatically geocoded into a lat/lon and a marker is put on a map, I'd love to see it and know how you did it.
Thanks,
Joel
I've tried but to no avail
Thanks Michelle. I've been on vacation and I'm just now getting back to this. I tried your settings and still no markers. I did save the node and that doesn't seem to have any effect. I also DO have a valid API key. Without know anything about the underlying structure of the code, my suspicion is that there is some conflict between location.module and gmap_location_module. There seems to be a lot of overlapping functionality between the two modules. That's just a hunch. Another thought is that maybe there is a versioning issue. I have been using the latest dev snapshot for 5.x-1.x-dev. Maybe geocoding worked at one point but is now broken. I'm getting pretty frustrated with this!
At this point I need to get this fixed so that I can move on with my site development. If there is someone out there who feels like they are an expert and can fix this, and would be interested in some consulting work, please let me know.
Thanks everyone for your responses. -David
You are correct
I'm not sure if/how it works with the 5.x version, but with the 4.7 version google geocoding was not compatable with location.module. In order to use google's geocoding, the module's built-in alternative for location.module had to be used. This is because it was very easy to implement as a javascript implementation that would do the geocoding live when you entered an address in the address line. However, this was difficult to make compatible with location.modules fields and it created conflicts with the methods that location.module's geocoding system used.
I'm not sure if geocoding is a working feature in the 5.x version (I have not yet installed the 5.x version of gmap.module), but I expect that it would still be difficult to implement and be compatible with location.module. I'm sure this can be solved, but I found it frustrating when I was developing gmap.module. I spent about 1 hour making a nice little hack work for gmap_location's built in functionality for location storage and it worked quite well. It had one problem in that hitting enter on the address line caused the form to be submitted, which I found frustrating, but if you remembered to hit TAB isntead, it was pretty cool to enter an address and immediately see the map change to reflect this location. However, I then spent a few hours trying to make it work with location module and found it too frustrating and gave up. My guess is nobody has moved the geocoding any further since then.
If you would like to see how it worked in 4.7 drop me a note and I will give you access to website where you can see it in action.
What if.....
How hard would it be to use gmap and gmap_location to do this without using location.module at all? The gmap module works when users enter location info on their profile page, so it makes me think that it wouldn't be hard to be able to add a "Gmap Location" field into a node and then instead of clicking the User Node map, another map could be generated showing the markers of the node locations. (I think the node locations link was supposed to do this - almost - by integrating with the location.module. It just doesn't seem to work for me and many others out there.)
I also am a Drupal noobie and couldn't php program myself out of a wet paper sack... Anyone else with better experience think this is possible?
Hi, I think I'm in the same
Hi,
I think I'm in the same situation as these folks here. I've tried every permutation of settings for GMap and location.module that I can think of, and still, the only places that show up on a map are those where I have directly input the longitude and latitude. I've even looked at the GMap code itself--the location fields are showing up as locpick_latitude and locpick_longitude, even.
I have two questions for the folks here who have gotten this to work, to help me troubleshoot.
I hope this will help me pinpoint why geocoding isn't working.
Maybe this will help
To tell the truth I haven't read the whole thread. It was originally on geocoding outside of the US. I'm answering a more general answer. As always, I'm detailing below one way to do the geocoding. I'm sure there are other ways, perhaps even more suitable for you.
Well, before geocoding to take place make sure to have your Google maps API key inserted in several Drupal settings menus: gmap module settings (admin => module settings => gmap), location module settings (admin => module settings => location => geocoding options tab => configure parameters). It took me while to find this out (several location for the same key...)).
I Use location module v5.x-1.x-dev, gmap v5.x-1.x-dev . The theme used is some custom theme.
The actual geocoding for nodes is executed (in my case) by the location module, using hook_nodeapi(). Have a look at location.module, line 776. In "op" (operation) "insert" and "update" the block of code which starts on line 852 is where the geocoding takes place. First, with location_latlon_exact() is used and if its not possible (no exact enough data to geocode with), with the postal code, via location_get_postalcode_data(). I hope you are familiar with the "hook_nodeapi" concept, which is an important feature/capability in Drupal.
What I suggest is that if you can, use some debugger to see what is occurring in your code when it enters the nodeapi phase, and what happens when the location_nodeapi() is being called with the above "op" parameters. Check what variables you have defined at that moment and their content. You can insert and use "watchdog()" function calls in the code to get useful info logged in Drupal logging system.
If all the above is too complicated or non-useful for you, you can use the following piece of code to perform geocoding:
<?php$html_output = file('http://maps.google.com/maps/geo?q='.$address.'&output=csv&key='.$myGmapAPIkey);
?>
I hope it helps... :)
Boaz
PHP therapist
Thank you, this does help.
Thank you, this does help. I think I had missed the second place to enter in the GMap API--I had originally missed the "Configure Parameters" on the Geocoding page because it was directly next to the Yahoo! Maps option, and I had mistakenly assumed it pertained to that API only.
Eureka!
That's it! Your message unlocked the hidden secret, boazry.
I also thought the link on that page was referring to Yahoo Maps Web Services, not Google.
Thanks!
Awsome! It works!
Thanks! it was the location module geocoding configuration. I'd feel pretty stupid, but it seems to have tripped others up too. Maybe it's time for a UI tweak! Thanks to everyone who has responded! -David
oh boy, this seems like a trap everyone falls at
Including myself! Some time ago I also bumped into geocoding issue and just "played" with the configuration. It seemed pretty awkward that the google API key needs to be entered in multiple different locations.
IMPORTANT: don't forget to update the key for all relevant countries - US, Canada in the location module settings. Yes, even inside the location module settings you need to enter it multiple times.
Now ain't these an important feature requests? : 1)having location module check for gmap module API key settings and use it, if exists. 2) Having all location module google API key synced, once entered into one country's settings. (hmm... contemplating whether to open the feature requests or try to produce them myself and submit the patch... do I have the time...).
Boaz.
Boaz
PHP therapist
Go for it
If you have time to write a decent settings page and make a patch, that would be great. The tricky part is getting the maintainer to apply it, though. The last time I checked (a month or so ago) there were a lot of unapplied patches. :( Still, people can apply it themselves if needed.
Michelle
Keys module as a solution
Hi,
Will the keys_api module help with this?
Greetings,
Martijn
YES, this helps
It helps a LOT! In March of 2008, it still helps. Man, was I stuck.
Thanks.
Tim Flanagan
Managing Editor
Navagear.com
Tim Flanagan
Managing Editor
Navagear.com
Geocoding based on zipcode when address is more specific
I've got geocoding to work, but I noticed that when I have a street address, city, zip code and country it brings in the latitude and longitude for the zip code rather then the address. However when I remove the zip code and re save the node it grabs the latitude and longitude for the specific street address. Where is this prioritization set? Is there a way to easily change it?
I guess I could move the zip code to a non-location enabled field so it's displayed for the user, but not noticed by the location module. but that doesn't seem like a very elegant solution.
how about this one?
www.drupal.org/project/gcg
This is the Google Client Gecooder module which does exactly this
****Me and Drupal :)****
Clickbank IPN - Sell online or create a membership site with the largest affiliate network!
Review Critical - One of my sites
Try resetting/defaulting the geocoding options
Try resetting/defaulting the geocoding options. It worked for me after trying to figure it out for 3 days!
-Joe