public static function Geocoder::geocode in Geocoder 7.2
Same name and namespace in other branches
- 8.3 src/Geocoder.php \Drupal\geocoder\Geocoder::geocode()
- 8.2 src/Geocoder.php \Drupal\geocoder\Geocoder::geocode()
Geocode a string.
Parameters
string|string[] $plugins: The name of the plugin to use or a list of plugins names to use.
$data: The string to geocode.
array $options (optional): The plugin options.
Return value
\Geocoder\Model\AddressCollection|FALSE
2 calls to Geocoder::geocode()
- geocoder in ./
geocoder.module - The Geocoder API call.
- geocoder_services_geocoder_geocode_callback in modules/
geocoder_services/ geocoder_services.services.inc - Callback for Geocoding service
File
- src/
Geocoder.php, line 29
Class
Namespace
Drupal\geocoderCode
public static function geocode($plugins = array(
'googlemaps',
), $data, array $options = array()) {
foreach ((array) $plugins as $plugin) {
$plugin = drupal_strtolower($plugin);
$plugin_options = isset($options[$plugin]) ? $options[$plugin] : array();
$plugin = self::getPlugin('Provider', $plugin, $plugin_options);
try {
return $plugin
->geocode($data);
} catch (InvalidCredentials $e) {
self::log($e
->getMessage(), 'error');
} catch (\Exception $e) {
self::log($e
->getMessage(), 'error');
}
}
$exception = new \Exception(sprintf('No plugin could geocode: "%s".', $data));
self::log($exception
->getMessage(), 'error');
return FALSE;
}