public function Geocoder::reverse in Geocoder 8.2
Same name and namespace in other branches
- 8.3 src/Geocoder.php \Drupal\geocoder\Geocoder::reverse()
- 7.2 src/Geocoder.php \Drupal\geocoder\Geocoder::reverse()
Reverse geocode coordinates.
Parameters
string $latitude: The latitude.
string $longitude: The longitude.
string[] $plugins: A list of plugin identifiers to use.
array $options: (optional) An associative array with plugin options, keyed plugin by the plugin id. Defaults to an empty array. These options would be merged with (and would override) plugins options set in the module configurations.
Return value
\Geocoder\Model\AddressCollection|null An address collection or NULL on gecoding failure.
Overrides GeocoderInterface::reverse
File
- src/
Geocoder.php, line 71
Class
- Geocoder
- Provides a geocoder factory class.
Namespace
Drupal\geocoderCode
public function reverse($latitude, $longitude, array $plugins, array $options = []) {
// Retrieve plugins options from the module configurations.
$plugins_options = $this->config
->get('plugins_options');
// Merge possible options overrides into plugins options.
$plugins_options = NestedArray::mergeDeep($plugins_options, $options);
foreach ($plugins as $plugin_id) {
// Transform in empty array a null value for the plugin id options.
$plugins_options += [
$plugin_id => [],
];
try {
$provider = $this->providerPluginManager
->createInstance($plugin_id, $plugins_options[$plugin_id]);
return $provider
->reverse($latitude, $longitude);
} catch (\Exception $e) {
static::log($e
->getMessage());
}
}
return FALSE;
}