草庐IT

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

coder 2024-07-03 原文

我有一个 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/

有关php - Google Directions XML Feed 停止工作 - 代码没有改变的更多相关文章

  1. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  2. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  3. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  4. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  5. ruby-on-rails - Rails 源代码 : initialize hash in a weird way? - 2

    在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has

  6. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  7. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  8. ruby - 在没有 sass 引擎的情况下使用 sass 颜色函数 - 2

    我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re

  9. ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作 - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request

  10. ruby-on-rails - s3_direct_upload 在生产服务器中不工作 - 2

    在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo

随机推荐