来自 Google 搜索 API“findplacefromtext”的 ZERO_RESULTS

使用 Google Place API“findplacefromtext”时遇到奇怪的行为。https://maps.googleapis.com/maps/api/place/findplacefromtext/json

当通过浏览器使用 API 来检查响应时。显示有效响应。附上截图。

http://img.mukewang.com/62abe5a200019ade15770772.jpg

当通过CURL on Linux Terminal或CURL in PHP或file_get_contents在 PHP 中使用 API 时,响应为:


{

   "candidates" : [],

   "status" : "ZERO_RESULTS"

}

这是谷歌 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 密钥有效且经过适当授权。


反应变化背后的原因是什么?


不负相思意
浏览 381回答 2
2回答

阿晨1998

对我来说很好。$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>';哪个打印:{&nbsp; &nbsp;"candidates" : [&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"formatted_address" : "Martínez, Buenos Aires Province, Argentina",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"geometry" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "location" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"lat" : -34.4811677,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"lng" : -58.5165812&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "viewport" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"northeast" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lat" : -34.47967187010728,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lng" : -58.5156313&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"southwest" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lat" : -34.48237152989272,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lng" : -58.51943089999999&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"name" : "Lollapalooza Argentina",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"photos" : [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"height" : 1536,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"html_attributions" : [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "\u003ca href=\"https://maps.google.com/maps/contrib/115749286027841945795\"\u003eA Google User\u003c/a\u003e"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"photo_reference" : "CmRaAAAAiIyTEnkgKjKYFyQZKesopF4_dwAP6h0ynKq0nO5e9AelAo9D0IPqASptGAbZ999ZcOfPIQnlQYie5KtO45bIkSAMOowBkROYcJLdntbS0WhsNhhQJaG5lxU8aCUTuyjGEhBnHL_HnTImzwkwS4OHVSN9GhRO_IGFKamDj_8OEIL3i9MGaCWsXQ",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"width" : 2048&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"place_id" : "ChIJg-5cj9SxvJURkm6B2DlkKL0",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"rating" : 5,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"reference" : "ChIJg-5cj9SxvJURkm6B2DlkKL0"&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"formatted_address" : "Av. Sta Fe 1, B1642 Martínez, Buenos Aires, Argentina",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"geometry" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "location" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"lat" : -34.4742948,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"lng" : -58.51265829999999&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "viewport" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"northeast" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lat" : -34.47292497010727,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lng" : -58.51127897010728&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"southwest" : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lat" : -34.47562462989271,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lng" : -58.51397862989273&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"name" : "Lollapalooza Argentina",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"place_id" : "ChIJUQmrWaqxvJURScOzSiIIk9o",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"rating" : 0,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"reference" : "ChIJUQmrWaqxvJURScOzSiIIk9o"&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;],&nbsp; &nbsp;"status" : "OK"}

饮歌长啸

您面临的问题是由于执行请求的原始计算机的 IP 地址不同。为了证明这一点,从 IP 偏差更改为区域,两个机器/浏览器/php 脚本应该返回相同的数据集。看更多:locationbias&nbsp;- 通过指定半径加上 lat/lng 或表示矩形点的两个 lat/lng 对,首选指定区域的结果。如果不指定该参数,则API默认使用IP地址偏置。IP 偏差:指示 API 使用 IP 地址偏差。传递字符串&nbsp;ipbias(此选项没有附加参数)。来源:https ://developers.google.com/places/web-service/search
打开App,查看更多内容
随时随地看视频慕课网APP