You are here

function geocoder_services_geocoder_reverse_callback in Geocoder 7.2

Callback for Revere Geocoding service

Parameters

string $plugin_id:

string $data:

string $output (optional):

Return value

object

1 string reference to 'geocoder_services_geocoder_reverse_callback'
geocoder_services_services_resources in modules/geocoder_services/geocoder_services.module
Implements hook_services_resources().

File

modules/geocoder_services/geocoder_services.services.inc, line 60

Code

function geocoder_services_geocoder_reverse_callback($plugin_id, $data, $output) {
  geocoder_services_check_request($plugin_id, $output);
  list($latitude, $longitude) = explode(',', $data, 2);
  if ($addressCollection = \Drupal\geocoder\Geocoder::reverse($plugin_id, $latitude, $longitude)) {
    $data = array(
      'count' => $addressCollection
        ->count(),
    );
    foreach ($addressCollection as $address) {
      $data['collection'][] = array(
        'raw' => $address
          ->toArray(),
        'formatted' => \Drupal\geocoder\Geocoder::getPlugin('Dumper', $output)
          ->dump($address),
      );
    }
  }
  else {
    $data = array(
      'count' => 0,
    );
  }
  return $data;
}