我没有从google地方文本搜索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);