I created a plugin to map a text address value to a Geofield field. This plugin depends on the Geocoder module and the Geofield module. Here is the code:


/**
 * @file
 * Convert an address into a geocoded point on a map
 */

$plugin = array(
  'form' => 'feeds_tamper_address_geofield_form',
  'callback' => 'feeds_tamper_address_geofield_callback',
  'name' => 'Address to Geofield',
  'multi' => 'loop',
  'category' => 'Other',
);

function feeds_tamper_address_geofield_form($importer, $element_key, $settings) {
  $form = array();
  $form['html'] = array(
    '#markup' => t('<p>This plugin will take an address string and convert it into a point on a map for storage in a Geofield field.</p>
                   <p>The input should be in a form you would type into Google maps (ie. 123 Main St., Anywhere, Ohio). The output should be mapped to a Geofield field (the "combined" value of the field).'),
  );
  return $form;
}

function feeds_tamper_address_geofield_callback($result, $item_key, $element_key, &$field, $settings) {
  if (module_exists('geocoder') && module_exists('geofield')) {
    geocoder_load_geophp();
    $point = geoPHP::load($field, 'google_geocode', 'point');
    $v = geofield_get_values_from_geometry($point);
    $field = array($v);
  }

}

Comments

twistor’s picture

Status: Active » Needs work

I like it. Do you think you could write a test for it? Look in feeds_tamper_plugins.test.

akoe’s picture

The plugin code workes like charm, except i needed to change in function feeds_tamper_address_geofield_callback()
the line

geocoder_load_geophp();

to

geophp_load();

since it seems not to be provided by geocoder anymore, but its dependency geoPHP does.

twistor’s picture

Title: Address to Geofield plugin » Add Feeds Tamper plugin
Project: Feeds Tamper » Geocoder
Issue summary: View changes

Actually, we have a plugin API, might as well use it correctly. No other plugins in Feeds Tamper have external dependencies.

pol’s picture

Status: Needs work » Closed (outdated)