使用Google Place API“ findplacefromtext”时出现奇怪的行为。 https://maps.googleapis.com/maps/api/place/findplacefromtext/json
通过浏览器使用API检查响应时。显示有效的响应。屏幕截图已附上。
当在PHP中通过CURL on Linux Terminal
或CURL in PHP
或file_get_contents
使用API时,响应为:
{
"candidates" : [],
"status" : "ZERO_RESULTS"
}
这是Google API。出于安全原因,未共享“ API KEY”: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?key=APIKEY&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry,reference,place_id&input=Lollapalooza+Argentina+Mart%C3%ADnez+Argentina
API密钥有效且经过适当授权。
改变反应的原因是什么?
答案 0 :(得分:0)
对我来说很好。
$url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?key=APIKEY&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry,reference,place_id&input=Lollapalooza+Argentina+Mart%C3%ADnez+Argentina";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
print '<pre>';
print $response;
print '</pre>';
哪些印刷品:
{
"candidates" : [
{
"formatted_address" : "Martínez, Buenos Aires Province, Argentina",
"geometry" : {
"location" : {
"lat" : -34.4811677,
"lng" : -58.5165812
},
"viewport" : {
"northeast" : {
"lat" : -34.47967187010728,
"lng" : -58.5156313
},
"southwest" : {
"lat" : -34.48237152989272,
"lng" : -58.51943089999999
}
}
},
"name" : "Lollapalooza Argentina",
"photos" : [
{
"height" : 1536,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/115749286027841945795\"\u003eA Google User\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAiIyTEnkgKjKYFyQZKesopF4_dwAP6h0ynKq0nO5e9AelAo9D0IPqASptGAbZ999ZcOfPIQnlQYie5KtO45bIkSAMOowBkROYcJLdntbS0WhsNhhQJaG5lxU8aCUTuyjGEhBnHL_HnTImzwkwS4OHVSN9GhRO_IGFKamDj_8OEIL3i9MGaCWsXQ",
"width" : 2048
}
],
"place_id" : "ChIJg-5cj9SxvJURkm6B2DlkKL0",
"rating" : 5,
"reference" : "ChIJg-5cj9SxvJURkm6B2DlkKL0"
},
{
"formatted_address" : "Av. Sta Fe 1, B1642 Martínez, Buenos Aires, Argentina",
"geometry" : {
"location" : {
"lat" : -34.4742948,
"lng" : -58.51265829999999
},
"viewport" : {
"northeast" : {
"lat" : -34.47292497010727,
"lng" : -58.51127897010728
},
"southwest" : {
"lat" : -34.47562462989271,
"lng" : -58.51397862989273
}
}
},
"name" : "Lollapalooza Argentina",
"place_id" : "ChIJUQmrWaqxvJURScOzSiIIk9o",
"rating" : 0,
"reference" : "ChIJUQmrWaqxvJURScOzSiIIk9o"
}
],
"status" : "OK"
}
答案 1 :(得分:0)
您面临的问题是由于与执行请求的原始计算机的IP地址不同。
要证明这一点,请从IP偏向更改为一个区域,并且两个机器/浏览器/ php脚本都应返回相同的数据集。
查看更多:
locationbias -通过指定 半径加上纬度/经度,或代表纬度的两个纬度/经度对 矩形的点。如果未指定此参数,则API 默认情况下使用IP地址偏差。
IP偏向:指示API使用IP地址偏向。传递字符串 ipbias (此选项没有其他参数)。