【问题标题】:How to fetch distance using curl? [closed]如何使用 curl 获取距离? [关闭]
【发布时间】:2012-03-06 11:47:48
【问题描述】:

我有这个网址

http://www.worldatlas.com/travelaids/driving_distance.htm

当我放

From city:
Hollywood, FL, United States
to city:
Washington Avenue, Miami Beach, FL, United States

我的距离是18.33mi / 29.51km

我需要一个 php 脚本,它将发送上述两个地址的 url,作为回报,我将获得上述距离。 我听说通过使用 CURL 我们可以得到这个,请帮助/指导,

谢谢

【问题讨论】:

    标签: php curl


    【解决方案1】:

    这样的事情应该可以工作:

    $origin = urlencode("Hollywood, FL"); $destination = urlencode("Washington Avenue, Miami Beach, FL"); $url = "http://maps.googleapis.com/maps/api/directions/json?origin=$origin&destination=$destination&sensor=false"; // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, $url);

    //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // $output contains the output string $output = curl_exec($ch);

    // close curl resource to free up system resources curl_close($ch);
    $arr = json_decode($output, TRUE); echo ""; print_r($arr); //get distance from this array

    参考:Google Maps Directions希望对您有所帮助

    【讨论】:

    • 使用 Google Directions API 的查询限制为每天 2,500 个路线请求。
    • @user1133643 - 你的意思是什么?
    【解决方案2】:

    我认为 Google API 会在这方面为您提供帮助。

    http://code.google.com/apis/maps/documentation/directions/

    另外,我认为本指南会对您有所帮助。

    http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/

    【讨论】:

    • 使用 Google Directions API 的查询限制为每天 2,500 个路线请求。
    • 如果您每天获得超过 2,500 个用户搜索,则意味着您的网站非常受欢迎并且可能会盈利。因此,在这种情况下,您可以获得商业版本。 code.google.com/apis/maps/documentation/premier 如果您尝试使用 worldatlas 网站执行此操作,则必须经常关注它们。因为如果他们修改了搜索条件,您的网站也需要更改。如果他们发现您的服务器 IP 每天向他们的服务器生成超过 2500 个请求,则有可能被阻止..
    • 非常正确,所以我认为必须购买 4 个高级套餐.....谢谢 4 这个帮助 :)
    猜你喜欢
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 2011-05-28
    相关资源
    最近更新 更多