Google Places API将搜索字符串与MySQL响应相结合

时间:2014-01-10 11:22:03

标签: javascript php mysql google-maps google-places-api

我正在尝试创建一个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));

1 个答案:

答案 0 :(得分:0)

您可能希望在完成$ row后关闭连接:

$row = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM City WHERE ID = $CityID"));
$BarCity = $row['CityName'];
mysqli_close($con);

查看http://nl3.php.net/mysqli_fetch_array#example-1728

处的mysqli_fetch_array用法示例
相关问题