I\'m gathering information on the location of stores. The search is:
Please try below code, I have used sleep(2) function for delay between requests, because next pagetoken needs to be validated on google server. You can even use looping to remove code repetation.
// your query here
$query = "";
// api key here
$api_key = "";
// api call code
try {
echo $url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" . $query . "&location=40.420989,-3.706812&radius=1000030&=&sensor=false&key=" . $api_key;
echo "
";
$result = file_get_contents($url);
$query_results = json_decode($result, true);
echo "First set" . "
";
print_r($query_results);
$next_page_token = $query_results['next_page_token'];
unset($query_results);
$query_results = array();
sleep(2);
echo $url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" . $query . "&location=40.420989,-3.706812&radius=1000030&=&sensor=false&key=" . $api_key . "&pagetoken=" . $next_page_token;
echo "
";
$result = file_get_contents($url);
$query_results = json_decode($result, true);
echo "Second set" . "
";
print_r($query_results);
$next_page_token = $query_results['next_page_token'];
unset($query_results);
$query_results = array();
sleep(2);
echo $url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" . $query . "&location=40.420989,-3.706812&radius=1000030&=&sensor=false&key=" . $api_key . "&pagetoken=" . $next_page_token;
echo "
";
$result = file_get_contents($url);
$query_results = json_decode($result, true);
echo "Third set" . "
";
print_r($query_results);
unset($query_results);
$query_results = array();
} catch (Exception $e) {
$e->getCode();
$e->getLine();
}