Posted by gagarine on January 31, 2010 at 12:39am
3 followers
| Project: | Geocode |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
My field have this content: "Botyre, 1966, Ayent, Switzerland,". But in the function geocode (geocode.inc) the $input array is like that after join: "Botyre, 1966, Ayent, Switzerland, ,field_computed_address][0][value"
So the google API request look like: http://maps.google.com/maps/geo?q=Botyre%2C+1966%2C+Ayent%2C+Switzerland...
And of course google don't find is way all the time...
Comments
#1
Ok... in the geocode.module function geocode the $input is like that:
$input
['value'] "Botyre, 1966, Ayent, Switzerland, "
['_error_element'] "field_computed_address][0][value"
I don't understand what is this _error_element but what don't send only $input['value'] for the geocoding?
#2
Yeah I'm trying to use geocode on a text field with multiple values.
Everything is almost like you've described — $input is an array of value, _weight, _error_element for EVERY input field of multi-value 'address' text field, including the 'Add another item' button.
I can filter off the empty values, but I don't know how to get rid of "Add another" stuff. It looks exactly like it's a text field. Comparing $input['value'] to 'Add another item' is an option, but...
#3
I resolve that by don't send the complete array but only $input['value']. See the patch for geocode.module. Not sure is the good way but it work for me.
#4
Thanks, but it's not that simple.
There's no [value] for field_address_add_more (see below) button and it's not an array.
I guess the problem is in geocode_widget.module which is most likely not suposed to work with multi-value fields.
I'm using a custom geocoder plugin so I can handle $input there without patching the module itself.
[field_address] => Array
(
[0] => Array
(
[value] => Some address 1
[_weight] => 0
[_error_element] => field_address][0][value
)
[1] => Array
(
[value] => Some address 2
[_weight] => 1
[_error_element] => field_address][1][value
)
[2] => Array
(
[value] =>
[_weight] => 2
[_error_element] => field_address][2][value
)
[field_address_add_more] => Add another item
)
#5
As I understand it from the code a multiple field is sent through to
gecodeone at a time. With the $delta being then used to save it into $values if a result is returned. So the above would go 'some address 1' geocode result put into $values[0]['geo'] then 'some address 2' geocode result put in $values[1]['geo'].Most standard CCK fields do put the value in $field[$delta]['value'], even as above. So it might be good enough to test isset($value['value']). What fields have people this part working with?
For now I've patched much like above, but been a bit more liberal about what gets sent by testing on it being an array:-
Index: modules/geocode_widget/geocode_widget.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/geocode/modules/geocode_widget/geocode_widget.module,v
retrieving revision 1.9
diff -u -r1.9 geocode_widget.module
--- modules/geocode_widget/geocode_widget.module 28 Jan 2010 02:02:22 -0000 1.9
+++ modules/geocode_widget/geocode_widget.module 5 Mar 2010 17:13:18 -0000
@@ -87,10 +87,10 @@
$type = 'wkt:'. $element['#geocode_fields'][$field]['return'];
$values = array();
-
if (is_array($form_state['values'][$field])) {
foreach ($form_state['values'][$field] as $delta => $value) {
- if ($geo = geocode($info['handler'], $value, $type, $info['options'])) {
+ $str_value = (is_array($value)) ? $value['value'] : $value;
+ if ($geo = geocode($info['handler'], $str_value, $type, $info['options'])) {
$values[$delta]['geo'] = $geo;
}
}
#6
OK. I've installed postal module as well. The field does place its values in [street1] [city] and so forth, there is no [value]. So I've written a simple additional function to clean up the array (removing _error_element and _weight elements as well as empty ones). Additional note on above the widget does just take the first value for a multiple field. Generally it seems to make sense that geocode() just deals with strings, and the widget works out how it wants to deal with arrays.
Patch attached. I'll test this further and submit some simpletests for all this in another issue in a while.