目前我正在使用以下代码:
$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;