1

我只是想输出渥太华输入酒店的格式化地址。结果给了我我需要的所有数据以及不需要的东西。我需要截断这个。有任何想法吗?

     $address = urlencode("Hotels, in Ottawa");

     $geocodeURL = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=hotels+in+Ottawa&sensor=false&key=mykey";
     $ch = curl_init($geocodeURL);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec($ch);
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);

     $geocode = json_decode($result);

     echo $result;

     //echo $formatted_address = $geocode->data[0]->formatted_address;
4

1 回答 1

2

看来我终于想通了。

 $geocodeURL = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=hotels+in+Ottawa&sensor=false&key=mykey";
 $ch = curl_init($geocodeURL);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $results = curl_exec($ch);
 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 curl_close($ch);

 $geocode = json_decode($results);

 for($i=0; $i<20; $i++){
 echo $formatted_address = $geocode->results[$i]->formatted_address;
 }
于 2012-07-06T16:05:58.037 回答