Here's a patch based on 6.x-dev that:
Changes to geocoder/google.inc
1) request JSON instead of XML. This gives an easier(IMO) to decipher structure of data(relies on PHP's json_decode).
2) return more data to location.module, namely: street,province,country,accuracy and postalcode.
Changes to location.module:
1) in exact_geocode, it will overwrite whatever the user put in with what is returned from the geocoder.
This works on the same assumption that location.module uses in the google geocoder, which is that the first Point returned with an accuracy >3(region-level) is an exact match and correct. YMMV.
This is my first patch, and I plan on creating at least admin level settings to turn on/off, if not possibly in the future allowing user feedback upon post.
comments welcome!
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | reverse_geocode.patch | 10.38 KB | EvanDonovan |
| #6 | loc_reverse_geocode_pt1.patch | 1.98 KB | EvanDonovan |
| #6 | loc_reverse_geocode_pt2.patch | 6.92 KB | EvanDonovan |
| #5 | location_addr_normal.diff.patch | 1.16 KB | furrymitn |
| #1 | googlegeocode_json_2.diff.patch | 2.85 KB | furrymitn |
Comments
Comment #1
furrymitn commentedUpdated patches to conform!!(wasn't in drupal base directory)
Comment #2
EvanDonovan commentedExcellent work! This is a critical feature for getting reverse geocoding to work in Location module, as is necessary for using Location with FeedAPI content, for example.
However, the patch did not work for me "out of the box". I had to make some heavy modifications to it just to get it to apply at all, and then I had to modify it more so that it would actually submit reverse geocoding requests to Google's geocoder when saving a location. Probably tomorrow I will post my modifications once they have been made live on my organization's site.
I should be adding in a field in the content types interface to specify whether you want regular geocoding or reverse geocoding on the Location field of a given content type, as well as adding in the latitude & longitude query string parameters to the google geocoder code to make the reverse geocoding work properly.
Comment #3
EvanDonovan commentedBy the way, I initially saw this issue in a response to another issue. Would you might referencing that one here so we could track the progress of both together?
Comment #4
EvanDonovan commentedThe scope of my patch might be larger than yours, I've realized, so if you think I should open a new issue for my patch, let me know.
I would say that your patch needs work though because I couldn't get it to apply - it said was malformed.
Comment #5
furrymitn commentedHere's the issue that I found kind of like this one:
http://drupal.org/node/316297
I've attached a new patch for location.module, the patch was reversed(DOH!).
I've tested both patches with a freshly downloaded 3.x-dev without complications.
What do you foresee in what you are doing? I'm all for non-duplication, and if what you are doing/want to do encompasses my patches/ideas - I'd rather see something more grandeous, with admin settings and the like..
Comment #6
EvanDonovan commentedRather than go into a long explanation of what I would like to see, here is the patch that I've created. It's in two parts, because it was easier for me to make that way. I don't think I made part 2 from the proper directory, so you'll have to specify which file to patch. Anyway, though, it does work.
Essentially, the way it works is to do reverse geocoding (get an address from a latitude/longitude) if the latitude & longitude are changed. Otherwise, it does regular geocoding. That was in line with my use case (getting location data for items imported via FeedAPI, where the feed just had latitude/longitude).
It's not exactly what you were going for, though, I think, so it might actually be more appropriate in the other issue rather than this one. I'll post over there also & see what people think.
Comment #7
manuj_78 commentedI dont have the patching functionality on my pc so can I request that the patched module be pasted here please or else if someone can tell me a simpler way to patch this in Windows (without needing to instal eclipse) then that would be appreciated
Comment #8
EvanDonovan commentedmanuj_78:
I would recommend you download Cygwin - it's a bash shell emulator for Windows. That will allow you to apply patch files as you would on Unix. I think there's a few more suggestions at http://drupal.org/patch/apply.
Comment #9
furrymitn commentedSo does the patch that you submitted cover both, or only what you outlined?
My patch is more of a - user enters address, geocoder submits the address for geocoding(for map placement), and uses the results from the geocoder to "normalize"(aka overwrite) the users' inputted address. For instance, if the user enters 123 anywhere, 49441. and the geocoder returns LAT,LON, 123 Anywhere Ave., Muskegon, MI 49441 USA. It makes those all available to location.module, and the patch to location.module also overwrites the user supplied info with whats returned. It does no checks at this point, doesn't care if the lat/lon changed, etc. My patch is quite simple minded, and at some point I could see your idea and mine meeting in the middle somewhere...
long winded enough?
Comment #10
manuj_78 commentedAfter the patch in #6 I get Fatal error: Call to undefined function location_load_locations() in C:\Users\name\Sites\acquia-drupal-site\acquia-drupal\sites\all\modules\location\location_node.module on line 38
This is a test windows pc
I have not applied any other patches.
Comment #11
EvanDonovan commentedMy patch only does reverse geocoding if the latitude & longitude are changed, although the conditional in the location.module could easily be changed so that it always did reverse geocoding.
I am not certain at this time what would be the best way to merge our two implementations. I didn't want to overwrite what users submitted into the location fields because I'm not sure how to determine what the accuracy is. Hopefully, some other people (such as geodaniel, the OP on the other issue) can comment & shed some light on the issue.
Comment #12
EvanDonovan commented@manuj_78:
That is not happening for me when I save locations with this patch applied. Note that I actually applied the patch to 6.x-3.1-rc1.
I also have all the Location modules enabled, as well as Gmap module: Location, Location Add Another, Location CCK, Location Fax, Location Phone, Location Search, Node Locations, User Locations.
I don't think that enabling all of them should be necessary, however. The location_load_locations() function is defined in the location.module file.
Comment #13
furrymitn commentedUnderstood - by "meet in the middle" I meant that you are approaching things from the lat/lon to address(reverse geocode) end and i'm at the address to lat/lon end.
Just an update on this issue that I intend to further my patch with either(or both) an admin option to enable/disable this somehow(per content-type maybe), and/or a way to interact with the user upon submission(user gets an option to accept the overwrite, if it's correct) and possible use of multiple data returned from the geocoder.
Comment #14
EvanDonovan commentedOk, cool. I think I get where you're coming from now, and I'm going to probably re-roll my patch in the next few days to make it apply better (& to be one patch). Then, I will move it over to #316297: Add a reverse lookup of the coordinates to obtain country and city (plus more?), which fits my use case better, and you can continue working on your approach in this issue. If our patches can ultimately meet in the middle, that's fine, but I think our approaches are different enough that for both of us to continue working in this issue will cause confusion.
Comment #15
bioborg commentedSo, how would I get this to reverse geocode my existing database of some 2000+ lat/longs in location, to add city state and zip code to existing locations?
Comment #16
summit commentedEDIT: Is this patch needed to be able to map georss to feedapi/feedmapper_location (cck_location or location?) fields? Until now I am unsuccesfull in this..
Can anyone give the right steps from feedapi/feedelement_mapper feedelelement_location_mapper to get
the georss and other location related fields to location-fields?
greetings, Martijn
Comment #17
EvanDonovan commentedSorry I haven't worked on this at all - I successfully used my patch in #6 to solve the use case I described. So I haven't had a need to work on it subsequently. If you can apply the patches & then tell me specifically issues that you encounter, I could try to help. But I won't have time to re-roll a patch on this in the near future.
Comment #18
henno.gous commentedhas this been committed to dev yet?
Comment #19
EvanDonovan commented@henno.gous: No, there would have to be a decision about which approach to take. Also, I don't think any of the maintainers (bdragon, ankur, YesCT (in effect)) have even seen this issue. You'd have to call it to their attention if you wanted something done, but I think that might be premature at this stage.
The patch is still at the "needs review" state. I recommend that you try it out if you need the feature. If we get a few reviews, and consensus that this is a good approach, then it can be marked "reviewed & tested by the community" and committed.
Comment #20
hlopes commentedThere's a stand alone module that does this task here. Still under development.
Comment #21
EvanDonovan commented@furrymitn: Did you ever work further on your patch?
Here is a new version of my patch (as just one patch), rolled against 3.x-dev.
Let me know if it doesn't apply for you, and I can try to re-roll.
Comment #22
EvanDonovan commented@Summit: For what you request in #16, you should look at the Location Feeds module.
Comment #23
Adam S commentedI would like very much to "change user-inputted address (or lat/lon) to geocoded address info" via Ajax in Drupal 7. Is there anybody working on this at this time?
Comment #24
EvanDonovan commented@Adam S: I've never done this via AJAX, or in D7 - I think that you could have a page callback that would call google_geocode_location() though, and then the response would be used to populate the regular location form.
I just ran into some issues with this code when trying to use it with Location Feeds module. See #1194588: $location['locpick']['user_latitude'] doesn't always override $location['latitude'] for an explanation. At some point, I may re-roll the patch, but I don't have time for now.
Comment #25
EvanDonovan commentedAnother thing I noticed is that Google doesn't use "SubAdministrativeArea" in its JSON responses anymore apparently.
Thus, the last part of the google_geocode_location() function should now be:
@HLopes: Did you ever work further on your module?
Comment #26
podarokall feature requests should be rolled against latest 7.x-3.x-dev and after commit can be backported to 6.x branch
Comment #28
hlopes commentedHi there,
no, never worked on it again. Had a couple persons asking me to take ownership of the module, but after that never heard from them again.
The last version had some actions available to mass reverse geocode nodes in a sub-module, and it's available in my sandbox.
http://drupalcode.org/sandbox/HLopes/1078432.git/commit/bd510dc
As for the D7 port, should be pretty straightforward, except for the actions bit.
Maybe i'll have some time to fiddle with this soon. Will report back if i do.
(that's some serious necro-posting :D )