I\'m fairly new to JSON, and I\'m trying to get the latitude and longitude of a geocoded city from the Google Maps API using curl. The function I\'m using is:
Note that it seems that results
contains an array (with only one item in it, here) of results ; and geometry
is one item inside one result.
Here, you can see that results' content is delimited by []
-- which indicates it's an array.
So, you have to first access the first result : $geoloc['results'][0]
Inside of which you'll have the geometry : $geoloc['results'][0]['geometry']
Which will allow you to get the latitude and longitude :
var_dump($geoloc['results'][0]['geometry']['location']['lat']);
var_dump($geoloc['results'][0]['geometry']['location']['lng']);
I suppose that, depending on the address you've searched on, you will sometimes have more than one item in the results
array.