geocoder-php / GeocoderLaravel

Geocoder service provider for Laravel
http://geocoder-php.org/GeocoderLaravel/
MIT License
701 stars 102 forks source link

How to get using('provider') to work #126

Closed mbukovac closed 6 years ago

mbukovac commented 6 years ago

General Information

GeocoderLaravel Version: Laravel Version: 5.6.14 PHP Version: 7.2.3 Operating System and Version: Vagrant/Homestead

Issue Description

When trying to use

$result = $geocoder->geocode($request->address)->using('google_maps')->get();

I get an error:

Object of class Geocoder\Provider\Chain\Chain could not be converted to string

As listed in the issue #118, the solution you stated was

My recommendation is to publish and customize the config file by adding a second google maps provider entry outside of the chain provider.

How would I do this?

Specifically, I am trying to use GoogleMaps and Yandex, so my geocoder.php looks like this:

'providers' => [
        Chain::class => [
            GoogleMaps::class => [
                env('GOOGLE_MAPS_LOCALE', 'en-US'),
                env('GOOGLE_MAPS_API_KEY'),
            ],
            Yandex::class => [],
            GeoPlugin::class  => [],
        ],
    ],

Without using(), I can geocode with both GoogleMaps or Yandex, no issues with using either one.

Thanks for the help, much appreciated!

mikebronner commented 6 years ago

Hi @mbukovac, the following configuration should do the trick:

'providers' => [
        GoogleMaps::class => [
            env('GOOGLE_MAPS_LOCALE', 'en-US'),
            env('GOOGLE_MAPS_API_KEY'),
        ],
        Chain::class => [
            GoogleMaps::class => [
                env('GOOGLE_MAPS_LOCALE', 'en-US'),
                env('GOOGLE_MAPS_API_KEY'),
            ],
            Yandex::class => [],
            GeoPlugin::class  => [],
        ],
    ],

Please feel free to re-open if that does not work for you. :)