Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Working demo</strong></p> <p>using javascript and jquery:- <strong><a href="http://jsfiddle.net/NmQdy/" rel="nofollow">Working demo</a></strong> - just press 'run' at the top of the page.</p> <p><strong>Yahoo's GEO API</strong></p> <p>I did something similar to this a while back using yahoo's <a href="http://developer.yahoo.com/yql/console/" rel="nofollow">GEO API</a>. You can look up the locality of a specific lattitude and longitude with the following YQL query:-</p> <pre><code>select locality1 from geo.places where text="40.714623,-74.006605" </code></pre> <p>You can see the XML that is returned in the YQL console <a href="http://developer.yahoo.com/yql/console/#h=select%20locality1%20from%20geo.places%20where%20text=%2240.714623,-74.006605%22%0A" rel="nofollow">here</a></p> <p>To get this XML from your javascript/php code you can pass the query as a GET string like:-</p> <pre><code>http://query.yahooapis.com/v1/public/yql?q=[url encoded query here] </code></pre> <p>This will return just the XML which you can parse using jquery's <a href="http://api.jquery.com/jQuery.parseXML/" rel="nofollow"><code>parseXML()</code> method</a></p> <p><strong>Example Jquery code</strong></p> <p>Here is some example javascript to do what you're after:-</p> <pre><code>// Lat and long for which we want to determine if in NY or not var lat = '40.714623'; var long = '-74.006605'; // Get xml fromyahoo api $.get('http://query.yahooapis.com/v1/public/yql', {q: 'select locality1 from geo.places where text="' + lat + ',' + long + '"'}, function(data) { // Jquery's get will automatically detect that it is XML and parse it // so here we create a wrapped set of the xml using $() so we can use // the usual jquery selecters to find what we want $xml = $(data); // Simply use jquery's find to find 'locality1' which contains the city name $city = $xml.find("locality1").first(); // See if we're in new york if ($city.text() == 'New York') alert(lat + ',' + long + ' is in new york'); else alert(lat + ',' + long + ' is NOT in new york'); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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