Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple providers #4

Closed
adambant opened this issue Dec 20, 2013 · 6 comments
Closed

Using multiple providers #4

adambant opened this issue Dec 20, 2013 · 6 comments

Comments

@adambant
Copy link

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
Copy link
Member

toin0u commented Dec 21, 2013

Hi Adam,

By multiple provider do you mean the ChainProvider ?

@adambant
Copy link
Author

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
Copy link
Member

toin0u commented Jan 12, 2014

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
Copy link
Author

I believe it does. Thanks. :-)

@willdurand
Copy link
Member

Cool! Can we close the issue then?

@adambant
Copy link
Author

Sure no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants