0

here's my decoded json output,

object(stdClass)#1 (3) { ["name"]=> string(34) "xxxxxxxxxxxxxxx" ["Status"]=> object(stdClass)#2 (2) { ["code"]=> int(200) ["request"]=> string(7) "geocode" } ["Placemark"]=> array(1) { [0]=> object(stdClass)#3 (5) { ["id"]=> string(2) "p1" ["address"]=> string(32) "xxxxxxxxxxxxxxx, USA" ["AddressDetails"]=> object(stdClass)#4 (2) { ["Accuracy"]=> int(8) ["Country"]=> object(stdClass)#5 (3) { ["AdministrativeArea"]=> object(stdClass)#6 (2) { ["AdministrativeAreaName"]=> string(2) "UT" ["Locality"]=> object(stdClass)#7 (3) { ["LocalityName"]=> string(4) "xxxxxxxxxxxxxxx" ["PostalCode"]=> object(stdClass)#8 (1) { ["PostalCodeNumber"]=> string(5) "xxxxxxxxxxxxxxx" } ["Thoroughfare"]=> object(stdClass)#9 (1) { ["ThoroughfareName"]=> string(7) "xxxxxxxxxxxxxxx" } } } ["CountryName"]=> string(3) "USA" ["CountryNameCode"]=> string(2) "US" } } ["ExtendedData"]=> object(stdClass)#10 (1) { ["LatLonBox"]=> object(stdClass)#11 (4) { ["north"]=> float(xxxxxxxxxxxxxxx) ["south"]=> float(xxxxxxxxxxxxxxx) ["east"]=> float(-111.7018448) ["west"]=> float(xxxxxxxxxxxxxxx) } } ["Point"]=> object(stdClass)#12 (1) { ["coordinates"]=> array(3) { [0]=> float(xxxxxxxxxxxxxxx) [1]=> float(xxxxxxxxxxxxxxx) [2]=> int(0) } } } } }

I can retrieve the zipcode (84058) by using

echo $geo->Placemark[0]->AddressDetails->Country->AdministrativeArea->Locality->PostalCode->PostalCodeNumber; 

but how in the world would I retrieve these objects?:

  1. ["north"]=> float(40.2824822)
  2. ["east"]=> float(-111.7018448)
  3. [0]=>float(-111.7032032)
  4. [1]=> float(40.2811332)

Thanks, i'm new to this.

asked Feb 25, 2012 at 2:23

2 Answers 2

1

You would retrieve it the exact same way you're retrieving the zipcode. Break it down so you can understand it:

// access the entire json object
$geo
// access the placemark object (which contains an array of data)
$geo->Placemark
// access the placemark object at index 0
$geo->Placemark[0]
// access the Extended Data object of the Placemark object
$geo->Placemark[0]->ExtendedData

And so on. So now you should be able to figure out how to reach all the way to the north, south, east and west elements.

echo $geo->Placemark[0]->ExtendedData->LatLonBox->north;
echo $geo->Placemark[0]->ExtendedData->LatLonBox->south;

etc...

answered Feb 25, 2012 at 2:37
Sign up to request clarification or add additional context in comments.

Comments

0
1. $geo->Placemark[0]->ExtendedData->LatLonBox->north;
2. $geo->Placemark[0]->ExtendedData->LatLonBox->east;
3. $geo->Placemark[0]->Point->coordinates[0];
4. $geo->Placemark[0]->Point->coordinates[1];

It's a lot easy to see if you try running it through a pretty printer:

object(stdClass)#1 (3) {
 ["name"]=> string(34) "xxxxxxxxxxxxxxx" ["Status"]=> object(stdClass)#2 (2) {
 ["code"]=> int(200) ["request"]=> string(7) "geocode"
 }
 ["Placemark"]=> array(1) {
 [0]=> object(stdClass)#3 (5) {
 ["id"]=> string(2) "p1" ["address"]=> string(32) "xxxxxxxxxxxxxxx, USA" ["AddressDetails"]=> object(stdClass)#4 (2) {
 ["Accuracy"]=> int(8) ["Country"]=> object(stdClass)#5 (3) {
 ["AdministrativeArea"]=> object(stdClass)#6 (2) {
 ["AdministrativeAreaName"]=> string(2) "UT" ["Locality"]=> object(stdClass)#7 (3) {
 ["LocalityName"]=> string(4) "Orem" ["PostalCode"]=> object(stdClass)#8 (1) {
 ["PostalCodeNumber"]=> string(5) "xxx"
 }
 ["Thoroughfare"]=> object(stdClass)#9 (1) {
 ["ThoroughfareName"]=> string(7) "S 325 W"
 }
 }
 }
 ["CountryName"]=> string(3) "USA" ["CountryNameCode"]=> string(2) "US"
 }
 }
 ["ExtendedData"]=> object(stdClass)#10 (1) {
 ["LatLonBox"]=> object(stdClass)#11 (4) {
 ["north"]=> float(xxx) ["south"]=> float(40.2797843) ["east"]=> float(-111.7018448) ["west"]=> float(xxxx)
 }
 }
 ["Point"]=> object(stdClass)#12 (1) {
 ["coordinates"]=> array(3) {
 [0]=> float(xxxxx) [1]=> float(xxxx) [2]=> int(0)
 }
 }
 }
 }
}
answered Feb 25, 2012 at 2:41

1 Comment

@DavidEugenePeterson Hi, sorry I forgot to link to it. I used this one: prettyprinter.de Checked a couple boxes to make it look a way I thought would be reasonably readable.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.