【问题标题】:How find Distance between two addresses through php如何通过php找到两个地址之间的距离
【发布时间】:2012-09-22 16:06:08
【问题描述】:

我正在寻找一些帮助来通过php找到两个地址之间的距离 因为我不能使用谷歌地图 api。所以从这篇文章中得到一个方法

Distance between two addresses

但我需要知道如何使用 URL 模式发送请求 并抓住休息将它们保存在数据库中。

http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false

感谢您的任何建议。

//////////////

这些答案之后我就在那里

     $customer_address_url =  urlencode($customer_address);
     $merchant_address_url =  urlencode($merchant_address);

     $map_url = "http://maps.google.com/maps/api/directions/xml?origin=".$merchant_address_url."&destination=".$customer_address_url."&sensor=false";

      $response_xml_data = file_get_contents($map_url);
      $data = simplexml_load_string($response_xml_data);

当我输入这个网址时,XML 响应是可见的:http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false

但不能通过打印

      echo "<pre>"; print_r($data); exit;  

【问题讨论】:

  • 感谢这些功能太有用了。我在那里设置了我的逻辑,但无法打印来自 $data = simplexml_load_string($response_xml_data); 的 xml 响应回声“
    ”;打印_r($数据);退出;

标签: php distance


【解决方案1】:

你可以试试这个..

$url = "http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false";
$data = file_get_contents($url);

现在$data 包含生成的 xml 数据。您可以使用.. 解析此 xml 数据。

http://php.net/manual/simplexml.examples.php

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 2015-01-21
    相关资源
    最近更新 更多