You are here

public function GeocoderApiEnpoints::reverseGeocode in Geocoder 8.3

Same name and namespace in other branches
  1. 8.2 src/Controller/GeocoderApiEnpoints.php \Drupal\geocoder\Controller\GeocoderApiEnpoints::reverseGeocode()
1 string reference to 'GeocoderApiEnpoints::reverseGeocode'
geocoder.routing.yml in ./geocoder.routing.yml
geocoder.routing.yml

File

src/Controller/GeocoderApiEnpoints.php, line 271

Class

GeocoderApiEnpoints
Class GeocoderApiEnpoints.

Namespace

Drupal\geocoder\Controller

Code

public function reverseGeocode(Request $request) {
  $latlng = $request
    ->get('latlng');
  $geocoders_ids = $request
    ->get('geocoder');
  $format = $request
    ->get('format');
  $geocoders = [];
  try {
    $geocoders = $this->entityTypeManager
      ->getStorage('geocoder_provider')
      ->loadMultiple(explode(',', $geocoders_ids));
  } catch (\Exception $e) {
    watchdog_exception('geocoder', $e);
  }
  if (isset($latlng)) {
    $latlng = explode(',', $request
      ->get('latlng'));

    // Retrieve plugins options from the module configurations.
    $options = $this
      ->setGeocodersOptions($request);
    $dumper = $this
      ->getDumper($format);
    $geo_collection = $this->geocoder
      ->reverse($latlng[0], $latlng[1], $geocoders, $options);
    if ($geo_collection && $geo_collection instanceof AddressCollection) {
      $this
        ->getAddressCollectionResponse($geo_collection, $dumper);
    }
  }
  return $this->response;
}