开发者

Google Directions XML Feed stopped working - code haven't changed

I have a PHP file that intercepts and XML google feed for creating directions. Nothing has changed yet the file now produces no results. I have no idea why. So I have set up a testing page in the hope one of you can see what the hell is going on.

It is as if the feed url has changed, but it hasn't as I've checked that.

Here is the test page, listing 2 post codes taken from a regular get expression. A similar script is also used on another part of our site that has failed too. It's as if we have been blocked.

http://www.golfbrowser.com/Actions/directions.php?start=S173ne&end=SL42ES

And the PHP

<?php 

$start = $_GET['start'];
$end = $_GET['end'];

$xml = simplexml_load_file('http://maps.googleapis.com/maps/api/directions/xml?origin='.$start.'&destination='.$end.'&sensor=false');


// data to fetch
$startlat = $xml->xpath("/DirectionsResponse/route/leg/start_location/lat");
$startlng = $xml->xpath("/DirectionsResponse/route/leg/start_location/lng");
$endlat = $xml->xpath("/DirectionsResponse/route/leg/end_location/lat");
$endlng = $xml->xpath("/DirectionsResponse/route/leg/end_location/lng");


$start = $xml->xpath("/DirectionsResponse/route/leg/start_address");
$end = $xml->xpath("/DirectionsResponse/route/leg/end_address");

$start = (string)$start[0];
$end = (string)$end[0];

$startlat = (string)$startlat[0];
$startlng = (string)$startlng[0];

$endlat = (string)$endlat[0];
$endlng = (string)$endlng[0];


// Route Information

$distance = $xml->xpath("/DirectionsResponse/route/leg/distance/value");
$duration = $xml->xpath("/DirectionsResponse/route/leg/duration/value");

$distance = (string)$distance[0];
$duration = (string)$duration[0];

$duration = round(($duration / 60), 0);

if ($duration > 60)
{
  $hours = round(($duration / 60),0). ' hour and ';
  $minutes = $duration % 60 . ' minutes';
}
if ($duration == 60)
{
  $hours = round(($duration / 60),0). ' hour';
  $minutes == '';
}
if ($duration >= 120)
{
  $hours = round(($duration / 60),0). ' hours and ';
  $minutes = $duration % 60 . ' minutes';
}
if ($duration < 60)
{
   $minutes = $duration % 60 . ' minutes';
}

$distancekm = round(($distance * 0.001), 1);
$distancem = round(($distance * 0.000621371192), 1);


// Directions

$directions = $xml->xpath("/DirectionsResponse/route/leg/step");





// Compilation

$outputo = '
<a class="dirtotal" onclick="titoall()"><b>Route Overview </b>'.$distancem.' miles ('.$distancekm.' km) <br />about '.$hours.' '.$minutes.'</a>';

$outputs = '<a class="dirstart" onclick="tito('.$startlat.', '.$startlng.')"><b>'.$start.'</b></a>';

$output = '';
$distancem = '';
$distancekm = '';
$duration = '';

$order = 0;

foreach ($directions as $direct) {

    $latitude = $direct->start_location->lat;
    $longitude = $direct->start_location->lng;

    $output .= '<a class="dir" onclick="tito('.$latitude.', '.$longitude.')"><span class="tit">'.($order += 1).'</span><div>';

    if($distancekm !== '') {

    $output .= 'Drive '.$distancem.' miles ('.$distancekm.' km) then ';

    }


    $instructions =  $direct->html_in开发者_StackOverflow社区structions;
    $duration = $direct->duration->value;
    $distance = $direct->distance->value;

    $distancekm = round(($distance * 0.001), 1);
    $distancem = round(($distance * 0.000621371192), 1);


    $output .= $instructions;

    $output .= '</div><span class="end"></span></a>';

}

$outpute =
'<a class="dirend" onclick="tito('.$endlat.', '.$endlng.')"><b>'.$end.'</b></a>';


// output

$outputs = $outputo.$outputs.$output.$outpute;

echo $outputs;


?>

Any ideas?

Marvellous


You hit a usage limit: https://developers.google.com/maps/documentation/directions/#Limits

Try caching Google's responses and showing them to future users searching for the same directions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜