Stack Exchange
BazingaGeocoderBundle, Google Maps Geocoding API, url is not working from geocoder, but works directly in browser
I want to use BazingaGeocoderBundle to retrieve long and lat from postal code
 https://github.com/geocoder-php/BazingaGeocoderBundle/blob/master/README.md
It was working when i used it without API_KEY, but of course soon stopped complaining about over-quota.  
1) When i registered to “Google Maps Geocoding API”, and added API_KEY to :
C:\Bitnami\wampstack-5.5.30-0\sym_prog\proj2_27\vendor\willdurand\geocoder\src\Geocoder\Provider\GoogleMapsProvider.php
const ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=key';
const ENDPOINT_URL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&key='; // just in case there is something wrong with private $useSsl = true; setting

If i try url from my browser - i am getting result with all coordinates:
If i try to use bazinga.geocoder, which was working perfectly previously (Of course if i try to use it without a key, i am getting over-quota error now).:
 $addArr = $this->container
                ->get('bazinga_geocoder.geocoder')
                ->using('google_maps')
                ->geocode($addrArr[$random_addr_index]);

i am getting the error now: 
 [Geocoder\Exception\NoResultException]
 Could not execute query http://maps.googleapis.com/maps/api/geocode/json?ad
 dress=E16%201BH&key=AIzaSyB01WnF2o3M3GzUqn5UWZ_dVffssRrVXaQ

If i copy url to the browser - it lists result. 
According documentation, Geocoder ships with the egeloen/http-adapter library by default: https://github.com/geocoder-php/Geocoder#http-adapters .
2)
If i configure adapter in config and services,
i am getting error:  Invalid type for path "bazinga_geocoder.adapter". Expected array, but got string .
C:\Bitnami\wampstack-5.5.30-0\sym_prog\proj2_27\app\config\config.yml
bazinga_geocoder:     
    providers:
        google_maps: ~
    adapter: geocoder_adapter

C:\Bitnami\wampstack-5.5.30-0\sym_prog\proj2_27\app\config\services.yml
services:
    geocoder_adapter:
        class: Geocoder\HttpAdapter\CurlHttpAdapter
        public: false

Where is my mistake? Does adapter here matters? What else i have to change in vendor\willdurand\geocoder\src\Geocoder\Provider\GoogleMapsProvider.php ?
3) How to configure an use correctly other suggested adapters?
* `BuzzHttpAdapter` to use [Buzz](https://github.com/kriswallsmith/Buzz), a lightweight PHP 5.3 library for issuing HTTP requests;
* `GuzzleHttpAdapter` to use [Guzzle](https://github.com/guzzle/guzzle), PHP 5.3+ HTTP client and framework for building RESTful web service clients;
* `SocketHttpAdapter` to use a [socket](http://www.php.net/manual/function.fsockopen.php);
* `ZendHttpAdapter` to use [Zend Http Client](http://framework.zend.com/manual/2.0/en/modules/zend.http.client.html).


This is when your address info is invalid.
In your case your address info:
http://maps.googleapis.com/maps/api/geocode/json?address=E16%201BH

Where is "address=E16%201BH" is the actual address as a URL encoded string.
As you can see this is not a valid address.
It should be something like this:
http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway%2C+Mountain+View%2C+CA

To make your code more future proof, you should put a try catch around your encoding function.
try {
    $addArr = $this->container
                ->get('bazinga_geocoder.geocoder')
                ->using('google_maps')
                ->geocode($addrArr[$random_addr_index]);
} catch (Exception $exception) {
     $addArr = false;
}

