geocoder-php / Geocoder

The most featured Geocoder library written in PHP.
https://geocoder-php.org
MIT License
3.94k stars 515 forks source link

[Google Maps] API access denied #941

Closed AlifAbhiesa closed 5 years ago

AlifAbhiesa commented 5 years ago

image Where i must placed the API KEY for google maps? because when i try manually it's working, like this image

AlifAbhiesa commented 5 years ago

And i already placed my API KEY in here, but still doesn't work

image

jbelien commented 5 years ago

Hello @AlifAbhiesa ,

Have a look at the constructor : https://github.com/geocoder-php/google-maps-provider/blob/master/GoogleMaps.php#L97 You'll see that the last parameter is your key.

So it should be something like this:

new GoogleMaps($client, null, 'myApiKey');
atymic commented 5 years ago

@AlifAbhiesa Did you get this resolved?

AlifAbhiesa commented 5 years ago

@atymic

i put the key manually on this function

image

on this file

image

FYI : i'm using composer

atymic commented 5 years ago

@AlifAbhiesa

You should not modify parts of the library, could you post the code you are using to do the geocode? You should just be using something like this:

use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;

$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = new \Geocoder\Provider\GoogleMaps\GoogleMaps($httpClient, 'YOURAPIKEYHERE');
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'en');

$result = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));

Note where I put YOURAPIKEYHERE, instead use your API there.

AlifAbhiesa commented 5 years ago

Thank you @atymic it's work for me ;)

atymic commented 5 years ago

No worries :smile:

jbelien commented 5 years ago

Haha I'm a bit confused here, that's exactly what I said here. 😋

The good new is that it's "fixed" ! 🎉