开发者

More than 7 results for Google local search?

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."&开发者_JAVA技巧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;


You are currently limited in most cases to a total of 64 results - across 8 pages of 8 results each - that you can retrieve with the Search API. The exceptions to this rule are Local and Blog. Local will return up to 4 pages of 8 results, for a total of 32, and Blog will return only the first 8.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜