Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing Google Geocoding JSON with PHP [closed]

I'm trying to parse the json response from the Google Geocode API but I'm having a little trouble understanding it.

For those unfamiliar with the Geocode API here is the URL: http://maps.google.com/maps/api/geocode/json?address=albert%20square&sensor=false

I'm using the following code to parse the request

<?php

$address = urlencode($_POST['address']);
$request = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=" . $address . "&sensor=false");
$json = json_decode($request, true);

?>

And I'm trying to output with the following:

echo $json['results'][0]['formated_address'];

I'm not sure why nothing is being echoed. I've also tried $json[0]['results'][0]['formated_address']. I know this is a noob question, but multi-dimensional arrays confuse me.

like image 746
Lee Price Avatar asked May 24 '12 10:05

Lee Price


1 Answers

echo $json['results'][0]['formatted_address'];

It helps if you spell it correctly ;-)

like image 200
DaveRandom Avatar answered Oct 14 '22 02:10

DaveRandom