簡體   English   中英

Google Places API將搜索字符串與MySQL響應連接在一起

[英]Google Places API concatenate search string with MySQL response

我正在嘗試創建一個Google地方信息網址,該網址可以重復使用,並與來自數據庫的響應串聯在一起。.使其無法正常工作,並且嘗試了好幾天沒有運氣! 如果我將兩個字符串從PHP回顯到我的網頁上,然后將其復制並粘貼,則兩個地址都會生成相同的Google Places結果,但是當我打印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));

在完成$ 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用法示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM