title: Reverse geocoding using Nominatim in PHP
body: <p>I am trying to perform some reverse geocoding in php. Unfortunately, I am getting an error.</p>
  
  <pre><code>$lon = 100.753;
  $lat = 13.69362;
  
  function getAddress($RG_Lat,$RG_Lon)
  {
    $json = "http://nominatim.openstreetmap.org/reverse?format=json&amp;lat=".$RG_Lat."&amp;lon=".$RG_Lon."&amp;zoom=27&amp;addressdetails=1";
    $jsonfile = file_get_contents($json);
    $RG_array = json_decode($jsonfile,true);
  
    foreach ($RG_array as $name =&gt; $value)
    {
        if($name == "display_name")
        {
            $RG_address = $value;
            break;
        }
    }
  
    return $RG_address;
  }
  
  $addr = getAddress($lat,$lon);
  echo "Address: ".$addr;
  </code></pre>
  
  <p>Here are the errors which I am getting.</p>
  
  <pre><code>&lt;b&gt;Warning&lt;/b&gt;:  file_get_contents(http://nominatim.openstreetmap.org/reverse?format=json&amp;amp;lat=13.69362&amp;amp;lon=100.753&amp;amp;zoom=27&amp;amp;addressdetails=1): failed to open stream: Connection timed out in &lt;b&gt;/home/public_html/myapp/get_loc.php&lt;/b&gt; on line &lt;b&gt;22&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  Invalid argument supplied for foreach() in &lt;b&gt;/home/public_html/myapp/get_loc.php&lt;/b&gt; on line &lt;b&gt;25&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Notice&lt;/b&gt;:  Undefined variable: RG_address in &lt;b&gt;/home/public_html/myapp/get_loc.php&lt;/b&gt; on line &lt;b&gt;34&lt;/b&gt;&lt;br /&gt;
  Address: &lt;br /&gt;
  </code></pre>
  
  <p>If I use below code in Angular then it is working fine.</p>
  
  <pre><code>showCountry($scope.latitude,$scope.longitude);
        function showCountry(lat, lon) {
                $.getJSON('//nominatim.openstreetmap.org/reverse?json_callback=?&amp;format=json', {lat: lat, lon: lon}, function(data) {
  
                   console.log(data.address.town);
                   console.log('suburb- '+data.address.suburb);
                   console.log('county/district -'+data.address.county);
                   console.log('state - '+data.address.state);
                   console.log(data.address.postcode);
                    console.log(data.address.country);
  
               });
            }
  </code></pre>
  
  <p>I can't perform this action on the client side; that's the reason I need to do it in php.</p>