title: How to get more than 20 results for nearby places using google api
body: <pre><code>&lt;?php
  {
      $references = array();
      $names = array();
  
      $lat="26.177194999999998";
      $long="91.77591333333334";
      $count=0;
  
      $placeSearchURL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$lat,$long&amp;radius=10000&amp;types=mosque&amp;sensor=true&amp;key=AIzaSyASP02W3Qwb75Ruep3isiGstqA7Y2HXjGw";
  
      $placeSearchJSON = file_get_contents($placeSearchURL);
      $dataArray = json_decode($placeSearchJSON);
  
      if(isset($dataArray-&gt;status) &amp;&amp;$dataArray-&gt;status == "OK") {
          foreach( $dataArray-&gt;results as $details) {         
              array_push($references, $details-&gt;reference);
              array_push($names, $details-&gt;name);
          }
      }        
      foreach ($names as $name) {
          echo $name."&lt;br&gt;";
      }    
      echo "next token".$dataArray-&gt;next_page_token."&lt;br&gt;";
      if(!empty($dataArray-&gt;next_page_token)) {
          echo "in the if statement"."&lt;br&gt;";
          $placeSearchURL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$lat,$long&amp;radius=10000&amp;types=mosque&amp;sensor=true&amp;key=AIzaSyASP02W3Qwb75Ruep3isiGstqA7Y2HXjGw&amp;nextpage=".$dataArray-&gt;next_page_token;
          $placeSearchJSON = file_get_contents($placeSearchURL);
          //echo "hello";
          $dataArray = json_decode($placeSearchJSON);
  
          if(isset($dataArray-&gt;status) &amp;&amp;$dataArray-&gt;status == "OK") {
              foreach( $dataArray-&gt;results as $details) {
                  array_push($references, $details-&gt;reference);
                  array_push($names, $details-&gt;name);
              }
          }
          echo "hello&lt;br&gt;"; 
      }
  
      foreach ($names as $name) {
          echo $name."&lt;br&gt;";  
      }
      echo "next token".$dataArray-&gt;next_page_token."&lt;br&gt;";
  
      if(!empty($dataArray-&gt;next_page_token)) {
          echo "in the if statement"."&lt;br&gt;";
          $placeSearchURL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$lat,$long&amp;radius=10000&amp;types=mosque&amp;sensor=true&amp;key=AIzaSyASP02W3Qwb75Ruep3isiGstqA7Y2HXjGw&amp;nextpage=".$dataArray-&gt;next_page_token;
  
          $placeSearchJSON = file_get_contents($placeSearchURL);
          //echo "hello";
          $dataArray = json_decode($placeSearchJSON);
          if(isset($dataArray-&gt;status) &amp;&amp;$dataArray-&gt;status == "OK") {
              foreach( $dataArray-&gt;results as $details) {
  
              array_push($references, $details-&gt;reference);
              array_push($names, $details-&gt;name);
          }
      }
      echo "hello&lt;br&gt;";         
  }
  foreach ($names as $name) {
      echo $name."&lt;br&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p>I get the same 20 results every time, and I have used pagination as you can see in my code. Every time I print the next page token I get a different one. </p>
  
  <p>I would really appreciate if someone could point out the error in my code because I am stuck with this for quite some time. You are also most welcome to give any kind of relevant suggestion.</p>