When geocode widget is configured to contain a geocoded value from another field, that field being "addresses", some filtering needs to be done.
As the code currently stands, geocode_widget grabs an array from form state values, and passes that to the geocoding engine. That should work fine for a text field, or an array of textfields. But not for a Select. For an "addresses" cck field, when the field is editted, the country and province are displayed as select controls. Therefore, when geocode_widget grabs the values, it only grabs the keys for the selected items.
The key format is such that the google geocoder can usually decipher the address, but not always.
For example:
- "Toronto,on,top_ca" => Hilltop Rd, Toronto, ON M6C, Canada
- "Toronto,on,ca" => Toronto, ON, Canada
- "TypoCity,on,ca" => California, USA
- "TypoCity,Ontario,ca" => Ontario, California, USA
- "TypoCity,Ontario,Canada" => Ontario, Canada
- "TypoCity,ON,Canada" => error
Also, the fields are supplied in reverse order.
Here is a patch that resolves the problem (patch file 1)
Furthermore, the user input may not be clean. Google will sometimes handle this. For example, if you enter a bogus street name, google will probably return a geo centered on your city, or on the zone of your postal code. On the other hand, if the postal code has a typo, google will typically return an error code. geocode_google will silently ignore the error, and the geo is set to NULL. On your own website, you could configure some validation on the geo, as in "If (GEO == NULL) then invalid" However, for my purposes, it is more important to return a geo and move on.
My solution was to swap the various fields in and out, until geocode successfully returned something.
For example, "Toronto,Ontario,M5E28,Canada" will fail, but "Toronto,Ontario,Canada" will give you a Geo centered on the city.
If you're using an "addresses" field and that's the behaviour you want, use patch 2 instead of patch 1.
PS: To the module maintainers: My Solution #1 violates your encapsulation. I suggest you specify an interface for other module developers, perhaps a callback, such that they can generate a sensible address string or array for you. In your code, if there's no callback specified, you would just do the same default you're doing now: grab the values form form_state. My Solution #2, you could add as a configurable object in geocode_widget: When Geocoding fails: () fail validation () reduce precision until geocoding succeeds () record warning in watchdog, or () do nothing.
Regards.
| Comment | File | Size | Author |
|---|---|---|---|
| patch_geocode_widget_cbd_addresses_2.patch | 4.8 KB | adamus_maximus | |
| patch_geocode_widget_cbd_addresses_1.patch | 2.44 KB | adamus_maximus |
Comments
Comment #1
BenK commentedSubscribing