Using multiple providers
Closed this issue · 6 comments
adambant commented
Having difficulty figuring out best way (or any way) to use multiple providers with the Laravel module. Could a few examples be given?
Thanks
Adam
toin0u commented
Hi Adam,
By multiple provider do you mean the ChainProvider
?
adambant commented
No, the ability to explicitly pick a provider. For now I ended up using the native Geocoder methods because I couldn't figure out how to add more than one provider in the config.php file.
toin0u commented
Sorry for the late response.. What about this ?
// get the current adapter provided in the config.php file
$adapter = App::make('geocoder.adapter');
// define providers
$providers = array(
new \Geocoder\Provider\BaiduProvider($adapter, 'api-key'),
new \Geocoder\Provider\OIORestProvider($adapter),
// ...
);
// register providers
Geocoder::registerProviders($providers);
// pick up one registered provider by its name
Geocoder::using('baidu');
try {
// geocode
var_dump(Geocoder::geocode('10 rue Gambetta, Paris, France'));
} catch (\Exception $e) {
echo $e->getMessage();
}
The config.php
file just gives you default adapter and default provider but you can do what do you after.. Is this answer your question ?
adambant commented
I believe it does. Thanks. :-)
willdurand commented
Cool! Can we close the issue then?
adambant commented
Sure no problem.