Hi All,
I am trying to get the value of a specific node in an XML file. My
code is below, I have added comments pointing out where I believe the
problem to be, specifically on this line:
$coordinates = $xml->Response->Placemark->Point->coordinates;
Which, for some reason is empty. I am running PHP4, is this possible
in 4? You will notice I have replaced one of the lines which only
worked with PHP5 (SimpleXMLElement).
Note that my code was based on this sample:
http://www.developer.com/db/article.php/3621981
I later looked at this one from the Google maps API documentation
http://code.google.com/support/bin/a...00&topic=11364
I can confirm that the XML is returned and valid.
Any help/suggestions much appreciated - I sat down 3hrs ago thinking
this would be a 30 min job! :o)
Thank you!
Simon.
<?php
// Your Google Maps API key
$key = "<MYGOOGLEAPICODE>";
// Desired address
$address = "http://maps.google.co.uk/maps/geo?q=<SOME POST
CODE>&output=xml&key=$key";
// Retrieve the URL contents
$page = file_get_contents($address);
// Parse the returned XML file
// $xml = new SimpleXMLElement($page); <-- PHP 5 Required
$xml = domxml_open_mem($page);
// Parse the coordinate string
$coordinates = $xml->Response->Placemark->Point->coordinates;
<---- This var is empty
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
$lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];
// Diags
print "lat" . $lat;
print "lng" . $lng;
print $coordinates; <---- Outputs nothing
?>