You are here

function la_geocode_worker in Location 7.3

Handler to process single location per batch run.

Parameters

$lid: Location ID to process.

$operation_details: Details, passed to batch.

$context: Context, that stores interbatch data.

1 string reference to 'la_geocode_worker'
la_batch_run in contrib/location_autofill/la.module
Helper function for batch creation.

File

contrib/location_autofill/la.module, line 120
Location autofill routines.

Code

function la_geocode_worker($lid, $operation_details, &$context) {
  $l = location_load_location($lid);
  module_load_include('inc', 'location', 'geocoding/google');
  $r = google_geocode_location($l);
  if ($r != NULL) {
    $l['latitude'] = $r['lat'];
    $l['longitude'] = $r['lon'];
    location_save($l, FALSE);
  }

  // Inform the batch engine that we are not finished,
  // and provide an estimation of the completion level we reached.
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] >= $context['sandbox']['max'];
  }

  // Store some results for post-processing in the 'finished' callback.
  // The contents of 'results' will be available as $results in the
  // 'finished' function (currently, la_batch_finished()).
  $context['results'][] = is_null($r) ? 'error' : $lid . ' : ' . $l['latitude'] . ':' . $l['longitude'];

  // Optional message displayed under the progressbar.
  $context['message'] = is_null($r) ? t('Error obtaining location: !lid', array(
    '!lid' => $lid,
  )) . ' ' . $operation_details : t('Updating location "@lid"', array(
    '@lid' => $lid,
  )) . ' ' . $operation_details;
  la_update_http_requests();
}