【问题标题】:How to get json file from google maps server?如何从谷歌地图服务器获取 json 文件?
【发布时间】:2017-02-08 15:12:29
【问题描述】:

我正在尝试制作简单的行程计算器,我在这里,不知道下一步该做什么,它似乎也有效,但它没有。

所以有一个问题,因为这段代码应该给我一个json文件,寻求一些建议:3

<form  action="#" method="get">
  <input type="text" name="origin" value="" placeholder="Origin">
  <input type="text" name="destination" value="" placeholder="Destination">
  <input type="submit" name="submit" value="wyslij">
</form>

<?php
//https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood4&key=YOUR_API_KEY
define("YOUR_API_KEY","AIzaSyDqFsGPY9bSMtjh8S3oYAr1o0cPkBgCV1g");

$origin = $_GET["origin"];
$destination = $_GET["destination"];

if(isset($origin) && isset($destination) && !empty($origin) && !empty($destination)){
  $url = "https://maps.googleapis.com/maps/api/directions/json?origin=".$origin."&destination=".$destination."&key=".YOUR_API_KEY;
  //echo $url;
  if(file_put_contents($url,true)) echo '<p>DZIALA</p>';
  $str = file_put_contents($url,true);
  $json = json_decode($str, true);
  echo '<pre>' . print_r($json, true) . '</pre>';
}
else{
  echo "sth";
}
?>

【问题讨论】:

  • 当我粘贴这个表单创建的链接时,我可以看到这个 json 文件

标签: php json google-maps


【解决方案1】:

您为什么不使用 Google 的 Distance Matrix API - 很容易使用? https://developers.google.com/maps/documentation/distance-matrix/start

你问的问题在这里讨论过:

Get driving distance between two points using Google Maps API

【讨论】:

    猜你喜欢
    • 2015-01-24
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多