title: Reverse geolocation contains empty array. What should I do?
body: <p>I am new to php and I am developing an application that involves reverse geolocation . I am sending my latitude and longitude from android application. The problems is that I gets value the first but if I try requesting again I get Undefined offset: 0 error. </p>
  
  <p>PHP CODE</p>
  
  <pre><code>$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$driverLatitude.','.$driverLongitude.'&amp;sensor=false');
  
             while($geocode == "false"){
              $geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$driverLatitude.','.$driverLongitude.'&amp;sensor=false');
              sleep(6);
              }
               $data = json_decode($geocode);
               $add_array  = $data-&gt;results;
  
               $add_array =$add_array[0];
               $add_array = $add_array-&gt;address_components;
               $country = "Not found";
               $state = "Not found";
               $city = "Not found";
               foreach ($add_array as $key) {
                 if($key-&gt;types[0] == 'administrative_area_level_2')
                 {
                   $city = $key-&gt;long_name;
                 }
                 if($key-&gt;types[0] == 'administrative_area_level_1')
                 {
                   $state = $key-&gt;long_name;
                 }
                 if($key-&gt;types[0] == 'country')
                 {
                   $country = $key-&gt;long_name;
                 }
               }
               echo "Country : ".$country." ,State : ".$state." ,City : ".$city ."&lt;br /&gt;";
  </code></pre>
  
  <p>Is there a way I can resend the request after sometime in php till I get a value.</p>