Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're trying to use JSONP here.</p> <blockquote> <p><strong>JSONP</strong></p> <p>If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request > is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.</p> <p>Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. </p> </blockquote> <p>See: <a href="http://api.jquery.com/jQuery.getJSON/">http://api.jquery.com/jQuery.getJSON/</a></p> <p>But the URL you're calling returns <strong>plain</strong> JSON, so the parsing fails with a syntax error and <code>getJSON</code> fails silently.</p> <p>Now when you try to change the geocode URL to use JSONP, you get a <code>404</code> error since Google has removed support for JSONP quite a while ago:</p> <ul> <li><a href="http://code.google.com/p/gmaps-api-issues/issues/detail?id=1872">http://code.google.com/p/gmaps-api-issues/issues/detail?id=1872</a> </li> <li><a href="http://blog.mikecouturier.com/2009/11/jsonp-and-google-maps-api-geocoder-not.html">http://blog.mikecouturier.com/2009/11/jsonp-and-google-maps-api-geocoder-not.html</a></li> </ul> <p><strong>In short:</strong><br> You cannot simply use the geocode api from Browser JavaScript anymore, you'll have to add a proxy script on your server.</p> <p>And even if the request would work, your code still has a bug in it:</p> <p><code>json.results</code> is an <strong>array</strong> of results, so it has no <code>geometry</code> property.</p> <p>You have to access the first element of the array in order to get to the actual object that has the <code>geometry</code> property:</p> <pre><code>json.results[9].geometry.location.lng </code></pre>
 

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