Hi,

I am trying to build a page where i pull out a number of reviews about
places to go from a database, each containing a postcode..

Now i am using Googles Directions API ad have written some code which
should pull out the distance in miles from XML.

See my code below:

class PostcodeSearch{

    public function LoadXml($origin, $destination){

        $xml = simplexml_load_file("http://maps.google.com/maps/api/
directions/xml?origin=".$origin."&destination=".
$destination."&sensor=false");

        foreach ($xml->xpath('//distance') as $distance):
            $lastvalue = $distance->value;
        endforeach;

        $total = $lastvalue * 0.00062137119;
        $total = number_format($total, 2);

        return $total;
    }
}

And then i putt the code out like this:

<?
while($row = mysql_fetch_array($review)){
       $text = strip_tags($row['body']);
       $intro = substr($text, 0, 600);

       $pcode = PostcodeSearch::LoadXML($_GET['search'],
$row['postcode']);
?>

Distance is <?=$pcode?> miles.

<? } ?>

The results should be shown on this page:

http://babiesinthecity.co.uk/test/?searchbutton=&search=M25

But notice i get errors, can someone please help me out?

A typical XML file which contains results is as such:

http://maps.google.com/maps/api/directions/xml?origin=m25%202Nu&destination=M25%202SW&sensor=false

Any ideas what i'm doing wrong?

Thanks

Kind regards
billy

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to