最近,我嘗試使用谷歌的地方API來搜索的地方。起初,它運作良好。然後我發現,當我通過查詢包含空格。反應總是不好的要求。但是,當我直接將查詢放入瀏覽器時,它運行良好。這是我的代碼,任何人都可以幫助我?如何在查詢包含空間時使用google放置api?
$url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=$name&location=$lat,$lng&radius=$raidus&types=restaurant&sensor=false&key=mykey";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Get the response and close the channel.
$response = curl_exec($ch);
例如,如果$ name是'restaurant',它就會起作用。但是如果$ name是'餐館食物',它說不好的要求。然而,我把網址放入瀏覽器,它再次運作。我嘗試清理查詢參數,但響應仍然表示不好的請求。我希望有人能幫助我。
urlencode()字符串 – 2012-09-03 07:32:26