You are here

function geocoder in Geocoder 7

Same name and namespace in other branches
  1. 7.2 geocoder.module \geocoder()

The Geocoder API call.

Given a handler and data, geocode the data into a geometry object using the handler.

@example: geocoder('google','4925 Gair Ave, Terrace, BC'); geocoder('google','New York City',array('geometry_type' => 'bounds'));

Parameters

string $handler: The geocoder handler to use. Call geocoder_handler_info() to get a list.

mixed $data: Data to be passed into the handler for geocoding. For example a address string.

array $options: Additional options to pass to the handler. Exact key / values to pass depend on the handler.

int $cache_type: DEPRECATED. All results are cached persistently.

bool $cache_reset: (optional) Ignore potentially matched cache record, and live fetch. Defaults to FALSE.

Return value

Geometry Returns a geoPHP geometry object. Generally a Point. See http://drupal.org/project/geoPHP and https://github.com/phayes/geoPHP/wiki/API-Reference

2 calls to geocoder()
geocoder_services_geocode in ./geocoder.services.inc
Callback for geocoding service.
geocoder_service_callback in ./geocoder.module
Page callback for AJAX / Geocoder service.
10 string references to 'geocoder'
geocoder_drush_backfill in ./geocoder.drush.inc
Drush command callback for 'geocoder-backfill'.
geocoder_field_attach_load in ./geocoder.widget.inc
Implements hook_field_attach_load().
geocoder_field_attach_presave in ./geocoder.widget.inc
Implements hook_field_attach_presave().
geocoder_field_widget_form in ./geocoder.widget.inc
Implements hook_field_widget_form().
geocoder_field_widget_settings_form in ./geocoder.widget.inc
Implements field_widget_settings_form().

... See full list

File

./geocoder.module, line 68

Code

function geocoder($handler, $data, $options = array(), $cache_type = 'DEPRECATED', $cache_reset = FALSE) {
  ctools_include('plugins');
  $processor = ctools_get_plugins('geocoder', 'geocoder_handler', $handler);
  if (!$processor) {
    return NULL;
  }

  // Attempt to retrieve from persistent cache.
  $geometry = $cache_reset ? NULL : geocoder_cache_get($handler, $data, $options);

  // No cache record, so fetch live.
  if ($geometry === NULL) {
    try {

      // Load the file.
      geocoder_get_handler($handler);
      $geometry = call_user_func($processor['callback'], $data, $options);
    } catch (Exception $e) {
      watchdog_exception('geocoder', $e);
      return NULL;
    }

    // Always save result into persistent cache.
    geocoder_cache_set($geometry, $handler, $data, $options);
  }
  if (!$geometry && variable_get('geocoder_log_empty_results', FALSE)) {
    watchdog('geocoder', t('No results for geocoding @data', array(
      '@data' => $data,
    )));
  }
  return $geometry;
}