Closed (fixed)
Project:
Geocoder
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
29 Feb 2012 at 09:12 UTC
Updated:
20 Mar 2018 at 10:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
phayes commentedComment #2
phayes commentedBy the way, have you checked out GeoField's "address" formatter?
Comment #3
cesareaugusto commentedI think I haven't such a formatter. The only display formatters I got available for my geofields are
No address formatter seems to be here :(
Comment #3.0
cesareaugusto commentedspell check error
Comment #4
phayes commentedAh. I think it's hidden away in "Descriptive text (accessibility)". Likely not exactly what you want.
Comment #5
phayes commentedSo this is the way I would like this handled:
1. A new function called geocoder_reverse that is analogous to the "geocoder" function. It will take a geoPHP object and return a string (or whatever)
2. Re-write geocoder_get_hanlders so that you can specify the "type" 'forward' or 'reverse' or 'both' -- defaults to both.
3. Handlers should define 3 new functions: reverse_callback, reverse_field_types, and reverse_field_callback to be "reverse" enabled. Some modules might ONLY define these so as to make them ONLY reversers....
4. Define a new widget geocoder_reverse, and follow similar patterns as the forward geocoder
Comment #6
cesareaugusto commentedFrom a user's perspective I would immagine it as the very inverse of geocode from an address field function. Given we already got a geofield type field, when creating a new address type field we should have the option geocode from a geofield.
Comment #7
cesareaugusto commentedAny news on the reverse geocoding thing? :)
Comment #8
phayes commented@cesaragusto,
I don't have the time to work on this. I am, however, willing to review patches.
Comment #9
cesareaugusto commented@phayes I am not a coder, but I would be glad to help somehow... perhaps testing or doing the UI thing...
Comment #10
giorgio79 commentedAdditional feature idea: If the user submits a partial address such as
USA
Dallas
75932
XY street
State is missing (TX), but Google will still geocode it. So, after a successful gecodoe, do a reverse geocode and fill in the blanks, so the user would be offered with:
USA
TX
Dallas
75932
XY street
Comment #11
cesareaugusto commentedThat would be pretty useful when it comes about zip codes of larges cities. They commonly have more than one zip code according to the zone we refer to. Users usually know the city main zip code, but not everyone knows the zip code of the current area.
Comment #12
giorgio79 commentedCollaborate? http://drupal.org/sandbox/nodoxi/1893210
Comment #13
cesareaugusto commented@giorgio79: i'm not much into the sandbox thing... would it be possible to release a standard archive as every module does? perhaps at least a first dev one...
Comment #14
shushu commentedHi all,
Since I needed reverse geocoding and found out the module and this issue, I decided to create the patch.
I actually used @phayes comment #5 as a nice guidelines, with some changes to make it fit to the use of ctools plugin format.
It works nicely for me, via another rules integration module I created to use it (hope to upload soon).
I will be happy to finetune as needed.
Comment #15
cesareaugusto commented@shushu: I would like to try out your patch! To which version of the module should the patch be applied to?
Comment #16
cesareaugusto commented@shushu: I applied the patch against the 1.2 (stable) version. I upgraded. Though I cannot find the "Reverse-geocode from another field" form element to edit the data of postal address fields. How to use it?
Comment #17
shushu commentedSorry if I wasn't clear.
I used the API via a new Rules module I made - http://drupal.org/project/geocoder_rules
Hope this helps,
Shushu
Comment #18
socialnicheguru commentedI am unclear.
the patch in #14 is against geocoder
what is geocoder_rules needed for?
thanks for explaining.
Comment #19
shushu commentedWhile Geocoder can be used directly wth some modules via their fields, it is mainly an API module.
As such, and in order to create the most flexible solution (as I see it), I created some Rules actions that uses the Geocoder as API calls.
I am not against developing more support for reverse geocoding directly with the fields, but since my needs focus on Rules integration, this was my solution.
So,
- The reverse geocoding works as API, and can be used directly.
- Using the Rules module you can call the API via actions.
- If you feel this works, but support without Rules is needed, I will try to find time and make it happen as well
Regards,
Shushu
Comment #20
cesareaugusto commented@shushu: Would it be hard to implement the reverse geocoding thing as the very inverse of the Geocoder? I mean having the possibility to choose "reverse geocoding" within the address fields setting (as geocoder does for geofields).
Comment #21
shushu commentedIt shouldn't be hard, but I don't have the spare time to make it happen.
It shouldn't be hard also to install Rules, the geocoder rules, and to make it happen without any additional coding right away. This will also allow you to learn Rules, which is a great and powerful module...
Comment #22
sylvaticus commented@shushu: hi.. could you explain a little bit how to use your patch?
In particular, what does the following fields mean in the action settings?
I think I got that "Address" and "Accuracy" are output variables that we can then use in the remaining of the rule chain, and "Language" maybe is the language we want to use when querying google ?? But "Handler" what is it?
I have a geofield with lat/lon, can I use the rule action to get only the country or would I get the whole address ?
Comment #23
sylvaticus commentedthink I got, and it's working :-)
Handling is just the word "google" :-)
Comment #24
sylvaticus commentedFor those interested, this is a D7 code snippet that uses the geocoder api as patched in #14 to reverse geocode a geofield (with embedded lat/lon coordinated) and put the address formatted in a computed field.
In this case I put just the country, but you can play with the $address object to get what you need (it uses computed_field rather than rules or geocoder_rules).
Comment #25
sylvaticus commentedComment #26
cesareaugusto commented@sylvaticus: Sorry for the dummy question.... though........ How to use your code (from a newbie perspective)? Is it a patch against the module?
Comment #27
steinmb commented@sylvaticus Could you pls. provide a patch containing #14 and your code from #24?
Comment #28
sylvaticus commentedThe code in #24 is just a (working) example of USAGE of the geocoder module as patched in #14.
Application case: in a comtent type you have a field with lat/long (type:geofield) and you want to save on an other field the corresponding country (or any other address elements).
Steps:
- download geocoder and patch it with #14
- download computed_field, a module that let you define the value of a field from php code (so, the user doesn't write or even see this field on editing a node, it is computed automatically);
- add to the content type a computed field and in its edit form insert the code in #24
- edit the code in #24 according to your needs (e.g. yr language instead of "und")
- now whenever a node is saved the computed field read the data in the geofield and uses the reverse feocoding feature provided by #14 to get the country.
Comment #29
shushu commented@steinmb, my way to implement my patch is using Geocoder Rules module I created, and a simple Rule example below:
What this rule do:
Hope this helps,
Shushu
Comment #30
cesareaugusto commentedJust discussing about user-friendliness and coherence with the geocoder module behavior...... wouldn't it be easier to the "average user" to have a "reversegeocode from an geofield" option in the address field?
Comment #31
shushu commentedYou are right, making proper support for address field should be created.
As for myself, I don't use the addressfield at all, and I don't have spare time to create this support.
I will be happy to help anyone who will try to develop it.
Comment #32
Robin_K commentedIt might be worth noting that this functionality is currently in GeoPHP,
geoPHP::load($geoWKT,'wkt')->out('google_geocode')returns the address of $geoWKT.This works with all the formats supported by GeoPHP.
Comment #32.0
Robin_K commentedsorry another spell mistake
Comment #33
mastermindg commentedThanks Robin_K
I spent a whole lot of time tracking this point down. It's important to mention that from a mobile device I'm only able to grab long/lat, so for a more friendly presentation this needs to be reverse-geocoded. I used the following code (along with smart_ip and geophp) to accomplish this:
Comment #34
AgentJay commentedthanks for the sample code,
I have installed the geophp module and the code works perfectly, but I only want the country value returned, is there an easy way to do this?
Comment #35
mastermindg commentedI figured out (after the previous post) that you can output the geocoded results as an array:
$mypoint = geoPHP::load($json,'json')->out('google_geocode','array');$mypoint is now an array and Country can be selected like so:
$user_country = $mypoint[5]->short_name;Comment #36
socialnicheguru commentedWarning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in geocoder_reverse() (line 395 of /var/aegir/platforms/7/modules/all/geocoder/geocoder.module
Comment #37
syawillim commentedIs it possible to reverse geocode from an attached image EXIF data? I'd like to categorize nodes by country if someone could help out with an example of the rule.
Comment #38
jelle_sThis patch was set to NW in #27, while it really shouldn't have been. Is there any reason why this isn't yet committed? Is something missing from this patch? It would be an awesome feature! It seems like I have a similar use case as #37, no doubt others will have use cases as well!
Comment #39
jgullstr commentedThe patch in #14 works nicely for me. As this functionality is not interfering with geocoders existing features, I think this can be commited -> RTBC.
I've created an addressfield widget for reverse-geocoding geofields into addressfield values by using the functionality provided by this patch: Addressfield reverse geocode widget. A similar approach to how this module works could be used to create addresses from EXIF data (@syawillim).
Comment #40
jgullstr commentedComment #41
Kostasm83 commentedHi, I tried a lot both of #29 and #28 ways but I didn't have any result.
In #29 way I have these errors:
Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in geocoder_reverse() (line 32 of /var/www/katastima/sites/all/modules/geocoder/geocoder.module).
Notice: Trying to get property of non-object in geocoder_rules_reverse_geocode() (line 23 of /var/www/katastima/sites/all/modules/geocoder_rules/geocoder_rules.module).
Notice: Trying to get property of non-object in geocoder_rules_reverse_geocode() (line 24 of /var/www/katastima/sites/all/modules/geocoder_rules/geocoder_rules.module).
Maybe i do something wrong... can You help pz...
Thank You.
Comment #42
zwerg commentedTrying this rules code:
I'll get the following error message:
Rules does not accept the value of
data_set" : { "data" : [ "node:field-location-name" ], "value" : [ "address" ]Is there any possibility to solve this?
Comment #43
xaa commentedI can't apply the patch on geocder-7.x-1.x-dev, any clue please ?
Comment #44
steinmb commentedYour right. The patch cannot be applied with git. Here is a re-roll that should work.
Comment #45
polHi all,
I'm working on the version 2.x of Geocoder, it's now based on Geocoder PHP library, which support geocoding and reverse geocoding out of the box.
You can find the repository here: https://github.com/drupol/geocoder
It's still in heavy development but it's getting along pretty nicely.
Let me know what you think.
Thanks.
Comment #46
haggins commentedHere's a reroll against current 7.x-1.3
@Pol
Unless version 2.x isn't stable it would be great to have this patch committed for all that depend on 1.x, like us ;)
Comment #47
jgullstr commentedSecond this.
Comment #48
DerTobi75 commentedThird that!
Comment #49
makbuk commented# 46 Works for me. Thanks.
Comment #51
polThanks !
Comment #52
pol