I have a hierarchical taxonomy tree: Country -> State -> City. And text fields: street, house number.
This patch provide optional feature: joins together all fields. Joining order is the same as the view order.

Features:

  1. Encode from taxonomy_reference_field
  2. Supported multiple terms in taxonomy_reference_field
  3. User can select more than one field in geocoder settings and they values joins together
  4. Refactored some functions

Comments

phayes’s picture

Assigned: Unassigned » phayes
Status: Patch (to be ported) » Needs work

I'e started working on this and have merged it into my private working copy. There's a lot of refactoring here (good stuff!), so it will require some additional modifications before I push it back to the main dev branch.

phayes’s picture

Title: Join values from multiple fields patch » Multiple-fields support (also concatenate multi-value handling)

This patch is badly broken. Allowing multiple fields is a good idea, but I it'll take a bit more time for me to implement properly.

Selecting multiple fields should be just like geocoding from a single-field with multiple deltas. Concatenate should merely be another option in the mutiiple-values handling option that is only valid for text-fields (and term-name fields etc).

phayes’s picture

P.S I'm still going to do this and re-factoring the widget processor into child functions was a good idea!

phayes’s picture

Okay, I've added concatenation support. Right now only support concatenation across deltas. Mult-field support will come later.

Note that if you need this functionality now you can use Computed Field: http://drupal.org/project/computed_field

phayes’s picture

Title: Multiple-fields support (also concatenate multi-value handling) » Multiple-fields support
zerkalica’s picture

i think, mult-field support not compatible with joining, It's different behaviours:
Create many geometries for each multi-field value of one field
Create one geometry for concatenation result of all multi-fields and single-fields values

In my example taxonomy field is multifield, but street and number is a single-value fileds.

Computed field powerfull, but uses php, it's hard to configure for non-php users.
Needed something like field parsing strategy presets or options. Geocoder sends array of fields with values and receives concatenated string and pass this string to handler plugin.

phayes’s picture

So I took a stab at this and basically came to the conclusion that working with heterogenous field-types is more or less going to be impossible. So I think the way we will solve this problem is to provide really good documentation and examples on how to use geocoder in combination with computed field (http://drupal.org/project/computed_field)

kurageart’s picture

would like to read some documentation as soon as possible...
Currently , i would need to geocode a computed field composed by a taxonomy reference and a text field...

farald’s picture

Hey! Why not solve this issue with tokens instead?

Let's say you have 2 options:
- Geocode from field
- Geocode from tokens

philippejadin’s picture

Geocode from tokens is a great idea. What the maintainers think ?

phayes’s picture

Title: Multiple-fields support » Geocode from Tokens

Yeah, definitely like the geocode from tokens. It's the right way to solve this problem. I'm updating the ticket name to reflect it.

bartezz’s picture

An example is much welcomed!

I have set it up with a computed field and told the geocode field to geocode from that particular computed field. The output from the computed field is correct and nicely comme separated. When I check the output of the computed field here I get different lat/long figures than thru geocode field. Looks like geocode field somehow points to the city center.

Cheers

bartezz’s picture

I've done some debugging and when I change line #241 in geocoder.widget.inc and comment out // return FALSE; then my computed field is taken into account.

Not sure if I need to open a new topic for a bug report?

Cheers

floretan’s picture

I think that geocoding from tokens is a good step, but it'd be great if we could (re-)use some of the rules module interface to load the geocoding data using the entity metadata api, making it possible to use either arbitrary entity fields/properties or to create a compound using tokens.

philippejadin’s picture

Ok, it took me some time to figure out, but here some nformations to geocode using computed field. This will allow you to geocode from multiple separated fields.

Let's say you want to geocode from 3 fields, simply concatenated like this :
[street] [postal_code] [city]

- Install the computed field module
- install the entity api module (I didn't find a way to make it otherwise. Drupal api to access field values is pita without it. Read this for background : http://drupal.stackexchange.com/questions/24699/whats-best-practice-when...)

- add a computed field to your node type
- add the following code to the computed field :

$node_wrapper = entity_metadata_wrapper($entity_type, $entity); // this creates a wrapper around your node, using entity api, so it will be easier to access each field value.

$street = $node_wrapper->field_street->value(); // one of this line for each of your "source" fields
$postal_code= $node_wrapper->field_postal_code->value();
$city = $node_wrapper->field_city->value();

$entity_field[0]['value'] = $street. ' , ' . $postal_code . ' ' . $city; // here we concatenate everything

Then setup geocoder to geocode from your new computed field. Save a test node with the fields correctly filled, and you should have your data correctly geocoded.

And voila !

semei’s picture

Thank you, this works. But as Bartezz mentioned, this only works if you change line #241 in geocoder.widget.inc and comment out // return FALSE;. Otherwise computed fields are not taken into account. Can this be done without having to worry about any other issues?

rudyard55’s picture

I'm interested in the answer for this also.

semei’s picture

I am now using rules to set the value of a certain text field upon creation/update of a node. That way I built my own computed field which can then be used for geocoding without having to mess with the module first.

rudyard55’s picture

Ok. I got that to work. Thank you for your help.

at this juncture, i'm operating on the premise that computed fields and geocoder are not compatible, because I've yet to see anything to contrary.

But using rules appears to work nicely.

philippejadin’s picture

I still think that token support would be much easier. The proposed solution I gave on #16 doesn't work anymore on -dev.

If I could put something like :

geocode from [adress-field], [postcode-field] [city-field], [coutry-field]

...using token, it would be a life saver. Curently I have no solution.

zmove’s picture

Same here, tested solution of #16 and commented the return false; line 241 of geocoder.widget.inc file and it doesn't work.

My computed field have the correct informations, but the geocoder field is still empty.

I looked to all posts about this issue that is quite old now and still doesn't found a decent solution ?

Do we have to abandon geofield + geocoder combination to the benefit of location that seems more maintained ?

philippejadin’s picture

Issue summary: View changes

This is very unfortunate that this issue is still open. I don't have the skills to work on it, and I guess the maintainer is too busy with other projects, which is understandable.

This module is critical for the future of geo in drupal. Together with geofield, this is the right mix of modularity and functionality, where other approach failed.

Any hope here ? :-)

s427’s picture

I found this discussion while searching for a solution for a similar problem. I have two fields, one for latitude and one for longitude, that are automatically populated with data extracted from images (via the exif module), and I need to bring those values together (in one field) so that the geocoder field can use it to display a map.

The solution I finally found is to use the Field default token module. This will allow you to use tokens as default value for any field when creating content.

Then you just need to create a new text field, and set its default value to use whatever value you need from other fields. In my case, the default value was : [file:field-gps-gpslatitude] / [file:field_gps_gpslongitude]

And finally, set the geocoder field to use this new field's value as its source.

The only problem (that I see) for this solution is that, since we're using tokens as a default value, the value of the new field is only automatically generated when the content is created. Not when the content is updated --then you would have to update the value of the new field manually. (It's not an issue in my case, though)

So it's a workaround, but I hope it helps someone.

rudiedirkx’s picture

rudiedirkx’s picture

Status: Needs work » Needs review
StatusFileSize
new4.13 KB

When (if) #2159925 gets in, you should use that instead of tokens. I gave it a go anyway. Try this on. It's funky and kinda messy, but it works perfectly, with multi value fields too.

It creates a new widget "Geocode from tokens", which replaces the "Geocode from field" setting with a "Geocode from tokens" textfield, where you could type "[user:field_addresses:postal-code] [user:field_addresses:country]" eg.

It probably won't work for taxonomy terms like this, because Taxonomy is weird: tokens are machine named "term" and the entity type is "taxonomy_term", or something like that, I don't remember and I didn't test with taxonomy.

nwom’s picture

Was really looking forward to using your patch, but it seems it is limited to nodes. On an entity bundles created via Redhen CRM, the fields are not shown.

In the meantime, I will create a computed field, instead of using your provided patch, but can't wait to use it if you decide to implement the functionality for entity bundles.

rudiedirkx’s picture

pol’s picture

Status: Needs review » Needs work

You forgot a dpm

+++ b/geocoder.widget.inc
@@ -157,7 +180,62 @@ function geocoder_field_attach_presave($entity_type, $entity) {
+  dpm($items, 'items');

Can you reroll the patch without the debug function ?

Thanks.

  • phayes committed a04efcf on 7.x-2.x
    Refactor and #1461914 -- adding concat support
    
    

  • phayes committed a04efcf on 8.x-2.x
    Refactor and #1461914 -- adding concat support
    
    
Koen.Pasman’s picture

I rerolled the patch to apply and work versus the latest 7.x-1.x branch for people who dont want to upgrade to 7.x-2.x.

Regarding the patch, some code improvements can be made I think, since I have no idea what the for() loop on line 232 is supposed to do.

pol’s picture

Status: Needs work » Closed (outdated)

Hi,

I really like the idea to geocode from token, but I also would like to have information on the for loop in the code.

nwom’s picture

Status: Closed (outdated) » Needs work

#32 still works and is in-use in my live environment without problems. @Pol, did you perhaps mean to change this to "Needs Work" based on your comment?