[英]No responses from google places text search api
我沒有收到Google Places文本搜索API的回復
這是我的PHP代碼:
$string=$row["PropertyTitle"].'+'.$row["LocalityName"].'+'.$row["CityName"];
$details_url="https://maps.googleapis.com/maps/api/place/textsearch/json?query=".$city."&key=someapikey";
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$geoloc = json_decode(curl_exec($ch), true);
print_r($geoloc);
它甚至沒有給出以下結果
{
"html_attributions" : [],
"results" : [],
"status" : "INVALID_REQUEST"
}
我在做什么錯誤?該如何解決?
您缺少$ch = curl_init();
而且我猜您的$string
應該命名為$city
。 另外,在$city
上使用urlencode
。 請參閱為什么我應該使用urlencode? 。
<?php
$city = urlencode( $row["PropertyTitle"].'+'.$row["LocalityName"].'+'.$row["CityName"] );
$details_url="https://maps.googleapis.com/maps/api/place/textsearch/json?query=".$city."&key=API_KEY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$geoloc = json_decode(curl_exec($ch), true);
print_r($geoloc);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.