Has Google geocoding api changed?

Hello!

Is there something new I missed? After three months, today I opened up a project of mine I was working on but the script I’m using for geocoding is not working anymore (it did back in october).

$city = "Szeged";
$street = "Vitéz u. 28";
$address = $city.'+'.$street;
      $geo_address = str_replace(" ", "+", $address);

      $json = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=$geo_address&key=AIzaSyAAQPA..........blablabla...............WzlPFmR6I");
      $json = json_decode($json);

      $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
      $lng = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};

It returns the following errors:

Notice: Undefined offset: 0 in C:\xampp2\htdocs\prand\proba.php on line 10

Notice: Trying to get property ‘geometry’ of non-object in C:\xampp2\htdocs\prand\proba.php on line 10

Notice: Trying to get property ‘location’ of non-object in C:\xampp2\htdocs\prand\proba.php on line 10

Notice: Trying to get property ‘lat’ of non-object in C:\xampp2\htdocs\prand\proba.php on line 10

Notice: Undefined offset: 0 in C:\xampp2\htdocs\prand\proba.php on line 11

Notice: Trying to get property ‘geometry’ of non-object in C:\xampp2\htdocs\prand\proba.php on line 11

Notice: Trying to get property ‘location’ of non-object in C:\xampp2\htdocs\prand\proba.php on line 11

Notice: Trying to get property ‘lng’ of non-object in C:\xampp2\htdocs\prand\proba.php on line 11

  1. use json_decode($json, true); Then you will get associative array only.

  2. Show your array at first with var_dump($json). It could be just changed format of google json. If not, if result is empty, then you wil know that is the URL problem.

1 Like

I’m such am idiot… :smiley: thanks, I would have never figured it out! My project was not linked with my billing account so my API key was disabled… :smiley:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.