views:

99

answers:

1

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;
+3  A: 

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

Mikey1980
Mikey1980
Nice! This is exactly what I was looking for. I have updated the question with the solution! Thanks again!
cdburgess
no worries man! Glad I could help.. may have to steal your code now, +1 for you question
Mikey1980
That's why I post it back. Share and share alike! Feel free to use away.
cdburgess