You are here

public function DumperPluginManager::setAddressFieldFromGeojson in Geocoder 8.2

Same name and namespace in other branches
  1. 8.3 src/DumperPluginManager.php \Drupal\geocoder\DumperPluginManager::setAddressFieldFromGeojson()

Define an Address field value from a Geojson string.

Parameters

string $geojson: The GeoJson place string.

Return value

array An array of the Address field value.

File

src/DumperPluginManager.php, line 62

Class

DumperPluginManager
Provides a plugin manager for geocoder dumpers.

Namespace

Drupal\geocoder

Code

public function setAddressFieldFromGeojson($geojson) {
  $geojson_array = Json::decode($geojson);
  $country_code = $this
    ->setCountryFromGeojson($geojson);
  $geojson_array['properties'] += [
    'streetName' => '',
    'postalCode' => '',
    'locality' => '',
  ];
  return [
    'country_code' => $country_code,
    'address_line1' => $geojson_array['properties']['streetName'],
    'postal_code' => $geojson_array['properties']['postalCode'],
    'locality' => $geojson_array['properties']['locality'],
  ];
}