Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to call 2 JavaScript methods in the same class?
    text
    copied!<p>i have this class with a few methods more code here <a href="http://jsbin.com/ilumov/27/edit" rel="nofollow">JS Bin</a></p> <pre><code>var Maps = (function () { function Maps() { } Maps.prototype.getCoord = function () { navigator.geolocation.getCurrentPosition(this.onPositionSuccess, this.onPositionError); }; Maps.prototype.getWatchCoord = function () { var options = { enableHighAccuracy: true, timeout: 3000 }; navigator.geolocation.watchPosition(this.onWatchSuccess, this.onWatchError, options); }; Maps.prototype.onPositionSuccess = function (position) { var pos = { 'latitude' : position.coords.latitude, 'longitude' : position.coords.longitude }; console.log(pos); }; Maps.prototype.onWatchSuccess = function (position) { var pos = { 'latitude' : position.coords.latitude, 'longitude' : position.coords.longitude }; console.log(pos); }; Maps.prototype.onWatchError = function (error) { console.log(error.code); }; Maps.prototype.onPositionError = function (error) { console.log(error.code); }; return Maps; })(); var maps = new Maps(); maps.getCoord(); </code></pre> <p>what i am trying to do is if <code>getCoord()</code> is a success then do a call to <code>getWatchCoord()</code> and compare the <code>latitude</code> and <code>longitude</code>. If they are the same don't run <code>getWatchCoord()</code></p> <p>Im trying to do this inside that Maps class if possible.</p> <p>I've tried a few ways but it seems i cant call <code>getWatchCoord()</code> inside <code>onPositionSuccess()</code> not i can set <code>var x = navigator.geolocation.getCurrentPosition....</code> and then <code>return pos;</code> inside the success callback &lt;- it wont return anything</p> <p>Any ideas?</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