Welcome to WebmasterWorld Guest from 54.145.221.99

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Help with Google Maps xml output

   
7:03 am on Jul 15, 2007 (gmt 0)

5+ Year Member



Hi,

I use PHP 5.0

I am trying to read the PostalCodeNumber node from the Google Maps xml output below:

$xmlstr = "<xml>
<Response>
<name>1600 amphitheatre mtn view ca</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark>
<address>
1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA
</address>
<AddressDetails Accuracy="8">
<Country>
<CountryNameCode>US</CountryNameCode>
<AdministrativeArea>
<AdministrativeAreaName>CA</AdministrativeAreaName>
<SubAdministrativeArea>
<SubAdministrativeAreaName>Santa Clara</SubAdministrativeAreaName>
<Locality>
<LocalityName>Mountain View</LocalityName>
<Thoroughfare>
<ThoroughfareName>1600 Amphitheatre Pkwy</ThoroughfareName>
</Thoroughfare>
<PostalCode>
<PostalCodeNumber>94043</PostalCodeNumber>
</PostalCode>
</Locality>
</SubAdministrativeArea>
</AdministrativeArea>
</Country>
</AddressDetails>
<Point>
<coordinates>-122.083739,37.423021,0</coordinates>
</Point>
</Placemark>
</Response>
</xml>"

$xml = new SimpleXMLElement($xmlstr);
$zipcode = $xml->AddressDetails->PostalCode->PostalCodeNumber;

for some reason it's not working. anyone got any ideas?

Thank you in advance for your help.

8:25 am on Jul 15, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



maybe something like this will work:

$zipcode = $xml->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->
PostalCode->PostalCodeNumber;
9:56 am on Jul 15, 2007 (gmt 0)

5+ Year Member



the example of the xml output that is on the Google Maps API Documentation page is not correct.

I checked the xml output that I get back from Google and it does not contain the node "SubAdministrativeArea"

this gave me what i wanted $xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->Locality->PostalCode->PostalCodeNumber

thank you for your help.

11:08 pm on Jul 15, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



and i just noticed i had missed the "Response->Placemark->" in my suggested solution based on their example...