Forum Moderators: coopster
I get the error: Fatal error: Cannot instantiate non-existent class: simplexmlelement
with the following snippet of code:
// Desired address
$url = "http://maps.google.com/maps/geo?q=$mapaddress&output=xml&key=$key";
// Retrieve the URL contents
$page = file_get_contents($url);
// Parse the returned XML file
$xml = new SimpleXMLElement($page);
// Parse the coordinate string
list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates);
// Output the coordinates
echo "latitude: $latitude, longitude: $longitude <br />";
Later i find SimpleXMLElement is not supported under PHP 4.x so i find this code snippet.
$getpage = file_get_contents($url);
$getpage = utf8_encode($getpage);
$responsedoc = domxml_open_mem($getpage);
$response = $responsedoc->get_elements_by_tagname("Response");
if ($response!=null) {
$placemark = $response[0]->get_elements_by_tagname("Placemark");
if ($placemark!=null) {
$point = $placemark[0]->get_elements_by_tagname("Point");
if ($point!=null) {
$cds = $point[0]->get_content();
$c = explode(",", $cds);
$_coords['lon'] = $c[0];
$_coords['lat'] = $c[1];
return $_coords;
echo "$_coords";
}
}
}
return null;
I was wondering if someone can advise where this should fit in / replace what existing code i have and to echo out the lat / long co-ordinates as above.
Many thanks
Marcus
echo "$_coords";
To something like this:
echo 'lon: '.$_coords['lon'].'<br/>lat: '.$_coords['lat'];
Also, why are you echoing the data after you are returning it? I'd return it and then echo the returned result accordingly from where the function is called.