You are here

public function GeocoderController::geocode in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_address/src/Controller/GeocoderController.php \Drupal\geolocation_address\Controller\GeocoderController::geocode()

Return coordinates.

Parameters

\Symfony\Component\HttpFoundation\Request $request: Current Request.

Return value

\Symfony\Component\HttpFoundation\JsonResponse Geocoded coordinates.

File

modules/geolocation_address/src/Controller/GeocoderController.php, line 53

Class

GeocoderController
Class AddressWidgetController.

Namespace

Drupal\geolocation_address\Controller

Code

public function geocode(Request $request) {
  $geocoder = $this->geocoderManager
    ->getGeocoder($request
    ->get('geocoder'), (array) $request
    ->get('geocoder_settings'));
  $address = $request
    ->get('address');
  $geocoded_result = $geocoder
    ->geocode($address);
  if (!isset($geocoded_result['location'])) {
    return new JsonResponse([]);
  }
  return new JsonResponse($geocoded_result['location']);
}