class Geocodio in Geolocation Field 8.3
Provides a Geocodio integration.
Plugin annotation
@Geocoder(
id = "geocodio",
name = @Translation("Geocodio"),
description = @Translation("See https://www.geocod.io/docs/ for details."),
locationCapable = true,
boundaryCapable = false,
frontendCapable = false,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geolocation\GeocoderBase implements ContainerFactoryPluginInterface, GeocoderInterface
- class \Drupal\geolocation_geocodio\Plugin\geolocation\Geocoder\Geocodio implements GeocoderInterface
- class \Drupal\geolocation\GeocoderBase implements ContainerFactoryPluginInterface, GeocoderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Geocodio
1 string reference to 'Geocodio'
- geolocation_geocodio.schema.yml in modules/
geolocation_geocodio/ config/ schema/ geolocation_geocodio.schema.yml - modules/geolocation_geocodio/config/schema/geolocation_geocodio.schema.yml
File
- modules/
geolocation_geocodio/ src/ Plugin/ geolocation/ Geocoder/ Geocodio.php, line 26
Namespace
Drupal\geolocation_geocodio\Plugin\geolocation\GeocoderView source
class Geocodio extends GeocoderBase implements GeocoderInterface {
/**
* {@inheritdoc}
*/
public function geocode($address) {
if (empty($address)) {
return FALSE;
}
// Get config.
$config = \Drupal::config('geolocation_geocodio.settings');
$fields = $config
->get('fields');
$location = [];
// Set up connection to geocod.io.
$geocoder = new GeocodioAPI();
$key = KeyProvider::getKeyValue($config
->get('api_key'));
$geocoder
->setApiKey($key);
// Attempt to geolocate address.
try {
// If fields are defined in settings pull associated
// metadata.
if (!empty($fields)) {
$fields = explode(',', $fields);
$result = $geocoder
->geocode($address, $fields);
}
else {
$result = $geocoder
->geocode($address);
}
} catch (RequestException $e) {
watchdog_exception('geolocation', $e);
return FALSE;
}
$results = $result->results[0] ?? FALSE;
// If no results, return false.
if (!$results) {
return FALSE;
}
else {
$location['location'] = [
'lat' => $results->location->lat,
'lng' => $results->location->lng,
];
}
// Add formatted address if it exists.
if (!empty($results->formatted_address)) {
$location['address'] = $results->formatted_address;
}
// Add metadata coming from fields if it exists.
if (!empty($results->fields)) {
$location['metadata'] = $results->fields;
}
return $location;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
GeocoderBase:: |
protected | property | Country formatter manager. | |
GeocoderBase:: |
protected | function | Get formatted address elements from atomics. | |
GeocoderBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
GeocoderBase:: |
public | function |
Attach geocoding logic to input element. Overrides GeocoderInterface:: |
4 |
GeocoderBase:: |
protected | function | Return plugin default settings. | 2 |
GeocoderBase:: |
public | function |
Return additional options form. Overrides GeocoderInterface:: |
2 |
GeocoderBase:: |
public | function | Return plugin settings. | |
GeocoderBase:: |
public | function |
Process the form built above. Overrides GeocoderInterface:: |
|
GeocoderBase:: |
public | function |
Reverse geocode an address. Overrides GeocoderInterface:: |
3 |
GeocoderBase:: |
public | function |
GoogleGeocoderBase constructor. Overrides PluginBase:: |
1 |
Geocodio:: |
public | function |
Geocode an address. Overrides GeocoderBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |