Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I...have been under the impression that the code I've been writing has been running asynchronously.</p> </blockquote> <p>Yes, it does. Your <code>geocode</code> function <em>cannot</em> return the results of the call to the Google API, because the function returns before the Google call completes. See note below:</p> <pre><code>function geocode(geocoder) { //do geocoding here... var address = "3630 University Street, Montreal, QC, Canada"; geocoder.geocode({ 'address': address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { // +---------- This doesn't return anything from your // v geocode function, it returns a value from the callback return results; } else { alert("Geocode was not successful for the following reason: " + status); } }); } </code></pre> <p>Instead, you must code your <code>geocode</code> function so that it accepts a callback which it will call when it has the results. E.g.:</p> <pre><code>// Added a callback arg ---v function geocode(geocoder, callback) { //do geocoding here... var address = "3630 University Street, Montreal, QC, Canada"; geocoder.geocode({ 'address': address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { // v---------- Call the callback callback(results); } else { alert("Geocode was not successful for the following reason: " + status); callback(null); // &lt;--- Call the callback with a flag value // saying there was an error } }); } </code></pre> <p>Then, instead of using it like this:</p> <pre><code>var results = geocode(someArgHere); if (results) { doSomething(results); } else { doSomethingElse(); } </code></pre> <p>You call it like this:</p> <pre><code>geocode(someArgHere, function() { if (results) { doSomething(results); } else { doSomethingElse(); } }); </code></pre> <p>E.g., you go <em>fully</em> asynchronous.</p>
    singulars
    1. This table or related slice is empty.
    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. 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