gpt4 book ai didi

php - Google Directions XML Feed 停止工作 - 代码没有改变

转载 作者:数据小太阳 更新时间:2023-10-29 02:46:22 25 4
gpt4 key购买 nike

我有一个 PHP 文件,用于拦截和用于创建方向的 XML 谷歌提要。什么都没有改变,但文件现在没有产生任何结果。我不知道为什么。所以我建立了一个测试页面,希望你们中的一个能看到到底发生了什么。

好像 feed url 已经改变了,但它没有,因为我已经检查过了。

这是测试页面,列出了从正则 get 表达式中获取的 2 个邮政编码。我们网站的另一部分也使用了类似的脚本,但也失败了。就好像我们被封锁了一样。

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

还有 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_instructions;
$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;


?>

有什么想法吗?

很棒

最佳答案

您达到了使用限制:https://developers.google.com/maps/documentation/directions/#Limits

尝试缓存 Google 的响应并将它们显示给 future 搜索相同路线的用户。

关于php - Google Directions XML Feed 停止工作 - 代码没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7456994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com