geocoder-php/GeocoderLaravel

Using multiple providers

Closed this issue · 6 comments

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

Hi Adam,

By multiple provider do you mean the ChainProvider ?

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.

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 ?

I believe it does. Thanks. :-)

Cool! Can we close the issue then?

Sure no problem.