谷歌本地搜索超过7个结果?

时间:2010-09-01 14:12:01

标签: php google-api google-local-search

目前我正在使用以下代码:

$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;

2 个答案:

答案 0 :(得分:3)

  

您目前受限最多   案件共64项结果 -   共8页8个结果 -   你可以用   搜索API。例外情况   规则是本地和博客。本地   将返回最多4页8   结果,总共32,和   博客只返回前8个。

来源:http://groups.google.com/group/Google-AJAX-Search-API/browse_thread/thread/db6616286ce83ca0

答案 1 :(得分:0)

这是不正确的 - 4页,每页8个结果,绝对是你可以检索的最大值。

本地搜索最多32个结果 - 64个结果是常规搜索的最大值。