Search code examples
phpgoogle-mapsgoogle-maps-api-3google-geocoderreverse-geocoding

Google Maps Api Geocoder Reverse Request in PHP


I'm using the following repo https://github.com/egeloen/ivory-google-map/ to get data from google maps.

I have the coordinates and i want to get the data from them. (Address, City, Country etc)

Code

$geocoder = new GeocoderService(
    new Client(),
    new GuzzleMessageFactory()
);
$geocoder->setKey("api key"); 
$request = new GeocoderCoordinateRequest(new Coordinate(38.01008020608845, 23.728229105472565)); 
$response = $geocoder->geocode($request);
print_r($response);

Every time i run the following code i get a status of REQUEST_DENIED.

I have enabled to my API the Geocoding API.

I have searched the documentation but i don't know where is the problem.

Any suggestions?


Solution

  • I just found out that my API key had a referrer restriction.

    The referrer restriction is for client-side request. I just created a new API key with no referrer restriction and everything worked.