我正在尝试创建一个Google Places网址,该网址可以重复使用,并与来自我的数据库的响应连接在一起。没有让这个工作,并且已经尝试了几天而没有运气!如果我回显两个字符串,从PHP到我的网页并复制并粘贴它,两个地址都会生成相同的Google地方信息结果,但是当我打印JSON解码的响应时,我从Google获得了UNKNOW_ERROR ..
这是我一直在努力使用的。第一个和第二个$ googlePlacesAPI包含完全相同的URL,只是一个连接而另一个是“硬编码”。
$googlePlacesAPI = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" .
$BarName. "+" . $BarCity . "&sensor=false&types=bar|night_club&key=" . $mySuperSecretKey;
$googlePlacesAPI = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" .
$BarName. "+" ."Göteborg". "&sensor=false&types=bar|night_club&key=" . $mySuperSecretKey;
要获取$ BarCity的值,我使用这段代码(在创建$ googlePlacesAPI变量之前):
$row = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM City WHERE ID = $CityID"));
mysqli_close($con);
$BarCity = $row['CityName'];
编辑: 这是我解释答案的方式:
$placesSearch = json_decode(file_get_contents($googlePlacesAPI));
答案 0 :(得分:0)
您可能希望在完成$ row后关闭连接:
$row = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM City WHERE ID = $CityID"));
$BarCity = $row['CityName'];
mysqli_close($con);
处的mysqli_fetch_array用法示例