Google 本地搜索结果超过 7 个?
目前我正在使用以下代码:
$zipcode = '91762';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large");
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
$data = ob_get_contents();
ob_end_clean();
curl_close($ch);
$restauraunts_array = json_decode($data, true);
foreach($restauraunts_array['responseData']['results'] as $key => $value) {
$results[] = array(
'title' => $value['titleNoFormatting'],
'address' => $value['streetAddress'],
'city' => $value['city'],
'state' => $value['region'],
'zipcode' => $zipcode,
'phone' => $value['phoneNumbers'][0]['number'],
'lat' => $value['lat'],
'lng' => $value['lng']
);
}
但它只会返回 7 个结果。我正在寻找一种方法来恢复更多。我查看了 API 代码,没有找到任何方法来获取更多结果。能做到吗?您能否指出如何获得多个结果的文档/实现?
回答:Mikey 能够提供我正在寻找的答案。以下是我为获得 32 个结果所做的操作:
$zipcode = '91762';
$results = array()
$counter = array(0,8,16,24);
foreach($counter as $page) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large&start=".$page);
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
$data = ob_get_contents();
ob_end_clean();
curl_close($ch);
$restauraunts_array = json_decode($data, true);
if(!empty($restauraunts_array['responseData']['results'])) {
foreach($restauraunts_array['responseData']['results'] as $key => $value) {
$results[] = array(
'title' => $value['titleNoFormatting'],
'address' => $value['streetAddress'],
'city' => $value['city'],
'state' => $value['region'],
'zipcode' => $zipcode,
'phone' => $value['phoneNumbers'][0]['number'],
'lat' => $value['lat'],
'lng' => $value['lng']
);
}
}
return $results;
Currently I am using the following code:
$zipcode = '91762';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large");
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
$data = ob_get_contents();
ob_end_clean();
curl_close($ch);
$restauraunts_array = json_decode($data, true);
foreach($restauraunts_array['responseData']['results'] as $key => $value) {
$results[] = array(
'title' => $value['titleNoFormatting'],
'address' => $value['streetAddress'],
'city' => $value['city'],
'state' => $value['region'],
'zipcode' => $zipcode,
'phone' => $value['phoneNumbers'][0]['number'],
'lat' => $value['lat'],
'lng' => $value['lng']
);
}
But it will only return 7 results. I am looking for a way to get back many more. I have looked through the API code and have not found any methods to get more results back. Can it be done? Can you point me to the documentation / implementation of how to get more than a few results?
ANSWER: Mikey was able to provide the answer I was looking for. Here is what I am doing to get 32 results:
$zipcode = '91762';
$results = array()
$counter = array(0,8,16,24);
foreach($counter as $page) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large&start=".$page);
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
$data = ob_get_contents();
ob_end_clean();
curl_close($ch);
$restauraunts_array = json_decode($data, true);
if(!empty($restauraunts_array['responseData']['results'])) {
foreach($restauraunts_array['responseData']['results'] as $key => $value) {
$results[] = array(
'title' => $value['titleNoFormatting'],
'address' => $value['streetAddress'],
'city' => $value['city'],
'state' => $value['region'],
'zipcode' => $zipcode,
'phone' => $value['phoneNumbers'][0]['number'],
'lat' => $value['lat'],
'lng' => $value['lng']
);
}
}
return $results;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来源:http: //groups.google.com/group/Google-AJAX-Search-API/browse_thread/thread/db6616286ce83ca0
source: http://groups.google.com/group/Google-AJAX-Search-API/browse_thread/thread/db6616286ce83ca0
这是不正确的 - 4 页,每页 8 个结果绝对是您可以检索的最大数量。
本地搜索最多有 32 个结果 - 常规搜索最多有 64 个结果。
This isn't correct - 4 pages with 8 results each is definitely the maximum you can retrieve.
It's 32 results max for local search - 64 results is the max for regular search.