title: PHP Get Address from longitude and latitude
body: <p>I create a code to get longitude and latitude of the user and this variables are stored in <strong>mysql</strong> database.</p>
  
  <p>I'm using this code below to have the address from longitude and latitude. </p>
  
  <p>After a search in <strong>stackoverflow</strong> i found this script but it didn't give me anything no error and no result. </p>
  
  <p>I tried to print the variable <strong>$geolocation</strong> and i have a result printed like this <strong>33.8943186,35.505271199999996</strong> but i don't have the full address :(</p>
  
  <p>Can any body please help me to solve my problem and get the exact address of user ??!!</p>
  
  <pre><code> $geolocation = $latitude.','.$longitude;
       $request ='http://maps.googleapis.com/maps/api/geocode/json?latlng='.$geolocation.'';
      $file_contents = file_get_contents($request);
      $json_decode = json_decode($file_contents);
      if(isset($json_decode-&gt;results[0])) {
          $response = array();
          foreach($json_decode-&gt;results[0]-&gt;address_components as $addressComponet) {
              if(in_array('political', $addressComponet-&gt;types)) {
                      $response[] = $addressComponet-&gt;long_name;
  print_r($response); // no error
              }
          }
  
          if(isset($response[0])){ $first  =  $response[0];  } else { $first  = 'null'; }
          if(isset($response[1])){ $second =  $response[1];  } else { $second = 'null'; } 
          if(isset($response[2])){ $third  =  $response[2];  } else { $third  = 'null'; }
          if(isset($response[3])){ $fourth =  $response[3];  } else { $fourth = 'null'; }
          if(isset($response[4])){ $fifth  =  $response[4];  } else { $fifth  = 'null'; }
  
          if( $first != 'null' &amp;&amp; $second != 'null' &amp;&amp; $third != 'null' &amp;&amp; $fourth != 'null' &amp;&amp; $fifth != 'null' ) {
              echo "&lt;br/&gt;Address:: ".$first;
              echo "&lt;br/&gt;City:: ".$second;
              echo "&lt;br/&gt;State:: ".$fourth;
              echo "&lt;br/&gt;Country:: ".$fifth;
  print_r($response);// No error
          }
          else if ( $first != 'null' &amp;&amp; $second != 'null' &amp;&amp; $third != 'null' &amp;&amp; $fourth != 'null' &amp;&amp; $fifth == 'null'  ) {
              echo "&lt;br/&gt;Address:: ".$first;
              echo "&lt;br/&gt;City:: ".$second;
              echo "&lt;br/&gt;State:: ".$third;
              echo "&lt;br/&gt;Country:: ".$fourth;
          }
          else if ( $first != 'null' &amp;&amp; $second != 'null' &amp;&amp; $third != 'null' &amp;&amp; $fourth == 'null' &amp;&amp; $fifth == 'null' ) {
              echo "&lt;br/&gt;City:: ".$first;
              echo "&lt;br/&gt;State:: ".$second;
              echo "&lt;br/&gt;Country:: ".$third;
          }
          else if ( $first != 'null' &amp;&amp; $second != 'null' &amp;&amp; $third == 'null' &amp;&amp; $fourth == 'null' &amp;&amp; $fifth == 'null'  ) {
              echo "&lt;br/&gt;State:: ".$first;
              echo "&lt;br/&gt;Country:: ".$second;
          }
          else if ( $first != 'null' &amp;&amp; $second == 'null' &amp;&amp; $third == 'null' &amp;&amp; $fourth == 'null' &amp;&amp; $fifth == 'null'  ) {
              echo "&lt;br/&gt;Country:: ".$first;
          }
        }
  print_r($response);// error
  </code></pre>