In the same way that the addressfield module's fields can be chosen as the source data for geocoding (via the "Geocode from field" select list, it would be great to have the fields from the location module do the same.

It's a pretty similar scenario to address field in that the location field collects one or more of city, state/region, country, postcode etc all of which could be aggregated together like geocoder_widget_parse_addressfield() does for address fields.

Comments

jeff h’s picture

Status: Active » Needs review
StatusFileSize
new4.9 KB

This was easier to add than I thought — your code is nice and easy to read :)

Patch attached.

phayes’s picture

Status: Needs review » Reviewed & tested by the community

This patch looks perfect

jeff h’s picture

Actually it isn't quite perfect :)

I had to modify the above patch very slightly — I discovered that Google can't geocode when it's given regions which are codes.

For example, Dunedin New Zealand is in a region called Otago, which has a region code of OTA. Google can't geocode "Dunedin, OTA, NZ" but geocodes perfectly when given "Dunedin, Otago, NZ" (or even just "Dunedin, NZ").

The following fixed the above patch for me. Instead of:

+ if (!empty($field_item['province'])) $address .= $field_item['province'] . ',';

...it needs to be:

  if (!empty($field_item['province']) && function_exists('location_province_name')) {
    $province_fullname = location_province_name($field_item['country'], $field_item['province']);
    $address .=  $province_fullname . ',';
  }
phayes’s picture

jeff h,

Can you re-roll your patch with the above change?

phayes’s picture

This is now committed. Thanks!

phayes’s picture

Status: Reviewed & tested by the community » Fixed
jeff h’s picture

Hey, sorry I didn't get a chance to do this. Thanks for the git attribution! :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.