Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use the Google Maps <a href="https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding" rel="nofollow">reverse geocoding API</a>. This allows you to map a lat, long pair to a set of addresses. For example:</p> <pre><code>function reverseGeoLookup(lon, lat) { //make a ajax request -- in prod just use whatever libraryyou have to provide this //probably jquery's $.get var req = new XMLHttpRequest() //put the longitude and latitude into the API query req.open("GET", "http://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+lon+"&amp;sensor=true", true) //this is just the result callback -- it's the function arg to $.get, essentially req.onreadystatechange = function() { if(req.readyState == 4) { //again jquery will parse for you, but we want the results field var result = JSON.parse(req.response).results //the maps API returns a list of increasingly general results //i.e. street, suburb, town, city, region, country for(var i = 0, length = result.length; i &lt; length; i++) { //each result has an address with multiple parts (it's all in the reference) for(var j = 0; j &lt; result[i].address_components.length; j++) { var component = result[i].address_components[j] //if the address component has postal code then write it out if(~component.types.indexOf("postal_code")) { var out = document.getElementById('output') out.innerHTML += component.long_name } } } } } //dispatch the XHR... just use jquery req.send() } </code></pre> <p>I put this example into a js fiddle too, <a href="http://jsfiddle.net/ef72Q/" rel="nofollow">here</a>.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload