You are here

public function Geocode::getParsedInput in Search API Location 8

Returns the parsed user input.

Parameters

array $input: The text entered by the user, contains either "value" or "lat"+"lng" as keys.

Return value

mixed Returns a string with "latitude,longitude" if we can find a location. NULL otherwise.

Overrides LocationInputInterface::getParsedInput

File

modules/search_api_location_geocoder/src/Plugin/search_api_location/location_input/Geocode.php, line 68

Class

Geocode
Represents the Raw Location Input.

Namespace

Drupal\search_api_location_geocoder\Plugin\search_api_location\location_input

Code

public function getParsedInput(array $input) {
  if (empty($input['value'])) {
    throw new \InvalidArgumentException('Input doesn\'t contain a location value.');
  }
  else {
    $active_plugins = $this
      ->getActivePlugins();
    $plugin_options = (array) $this->geocoderConfig
      ->get('plugins_options');

    /** @var \Geocoder\Model\AddressCollection $geocoded_addresses */
    $geocoded_addresses = $this->geocoder
      ->geocode($input['value'], $active_plugins, $plugin_options);
    if ($geocoded_addresses) {
      return $geocoded_addresses
        ->first()
        ->getLatitude() . ',' . $geocoded_addresses
        ->first()
        ->getLongitude();
    }
  }
  return NULL;
}