【发布时间】: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