Google Map api返回400 Bad请求

时间:2017-03-08 09:49:52

标签: php google-maps-api-3

我的代码

<?php
$origin = $_POST['origin'];
$address = explode("\n",$_POST['addresses']);
$address = implode("|",$address);
$data = array('origin'=>$origin,
          'destination'=>$origin,
          'waypoints'=>'optimize:true|'.$address,
          'key'=>'MYAPIKEY',
          'sensor'=>'false');
$data = http_build_query($data);
$url = "https://maps.googleapis.com/maps/api/directions/json?".$data;
echo file_get_contents($url);
?>

$ _ POST ['origin'] =“Frimurarvägen20,Skärholmen”

$ _ POST ['addresses'] =“Vasagatan 7,111 20 Stockholm \nKungsträdgårdsgatan20,11147 Stockholm \nUlvsundavägen160,16867 Bromma \ nHuvudstagatan 2A,171 44 Solna”

我尝试了什么: Urlencode post param。 str_replace%20

的空格

1 个答案:

答案 0 :(得分:-1)

Google Map api不接受åäö