title: Reverse Geocoding: Get city and country
body: <p>I want to use reverse geocoding to get the city and country of coordinates.</p>
  
  <p>Here are two examples:</p>
  
  <p><a href="https://maps.googleapis.com/maps/api/geocode/json?latlng=53.5510846,9.9936818&amp;lang=en" rel="nofollow">Hamburg, Germany</a></p>
  
  <p><a href="https://maps.googleapis.com/maps/api/geocode/json?latlng=13.7251097,100.3529126&amp;lang=en" rel="nofollow">Bangkok, Thailand</a></p>
  
  <p>I always need the first <code>address_components</code> and then the two types with the values <code>[ "locality" ]</code> and <code>[ "country", "political" ]</code> but I don’t know how to target them.</p>
  
  <p>What I have so far:</p>
  
  <pre><code>$url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . get_wpgeo_latitude( $post_id ) . ',' . get_wpgeo_longitude( $post_id ) . '&amp;language=de';
  $data = @file_get_contents( $url );
  $jsondata = json_decode( $data, true );
  
  print_r( $jsondata['results'][0]['address_components'][0]);
  </code></pre>