调用google directions api时PHP在mysql循环上崩溃
我在MySQL搜索查询中运行以下函数,通常可以找到大约100个结果。该函数使用GoogleAPI检索两个位置之间的距离 这个问题看起来像是循环正在使脚本崩溃,超过10个结果 有没有办法解决这个问题 暂停等待谷歌的回电 任何建议都有帮助调用google directions api时PHP在mysql循环上崩溃,php,Php,我在MySQL搜索查询中运行以下函数,通常可以找到大约100个结果。该函数使用GoogleAPI检索两个位置之间的距离 这个问题看起来像是循环正在使脚本崩溃,超过10个结果 有没有办法解决这个问题 暂停等待谷歌的回电 任何建议都有帮助 function get_driving_information($start, $finish, $raw = false) { if(strcmp($start, $finish) == 0) { $time = 0;
function get_driving_information($start, $finish, $raw = false)
{
if(strcmp($start, $finish) == 0)
{
$time = 0;
if($raw)
{
$time .= ' seconds';
}
return array('distance' => 0, 'time' => $time);
}
$start = urlencode($start);
$finish = urlencode($finish);
$distance = 'unknown';
$time = 'unknown';
$url = 'http://maps.googleapis.com/maps/api/directions/xml?origin='.$start.'&destination='.$finish.'&sensor=false';
if($data = file_get_contents($url))
{
$xml = new SimpleXMLElement($data);
if(isset($xml->route->leg->duration->value) AND (int)$xml->route->leg->duration->value > 0)
{
if($raw==true)
{
$distance = (string)$xml->route->leg->distance->text;
$time = (string)$xml->route->leg->duration->text;
}
if($raw=="miles")
{
$distance = (string)$xml->route->leg->distance->value / 1000 / 1.609344;
$distance = number_format($distance,1)." miles";
$time = (string)$xml->route->leg->duration->text;
}
else
{
$distance = (int)$xml->route->leg->distance->value / 1000 / 1.609344;
$time = (int)$xml->route->leg->duration->value;
}
}
else
{
throw new Exception('Could not find that route');
}
//return array('distance' => $distance, 'time' => $time);
return $distance;
}
else
{
throw new Exception('Could not resolve URL');
}
}
每秒有10个请求的限制,请在此处查看有关限制的更多信息:
你能描述一下“崩溃”是什么意思吗?有错误消息吗?谢谢,混蛋。除了谷歌的力量,还有其他选择吗?