2017-02-08 2 views
0

私は単純に旅行電卓を作ろうとしています。私はここにいるので、次に何をするべきかわからず、うまくいくように思えますが、そうではありません。そこで問題は、このコードbecouse、そこにあるアップjsonファイルをGoogleマップサーバーから取得するには?

は、いくつかのアドバイスの男を探して、私にJSONファイルを与える必要があります:あなたはGoogleからの距離行列のAPIを使用していない理由を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"; 
} 
?> 
+0

私はこのフォームで作られたリンクを貼り付けるとき、私は、このJSONファイルを見ることができます – Ferror

答えて

関連する問題