Skip to content

Commit

Permalink
To fix #3. (#21)
Browse files Browse the repository at this point in the history
* To fix #3.

clearWatch when the element is detached from DOM.

* Fix stuffs.

* Update geo-location.html

* Update geo-location.html
  • Loading branch information
motss authored and ebidel committed Aug 7, 2016
1 parent 46664c1 commit 9eee56a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions geo-location.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,29 @@
* @param {Number} detail.longitude Longitude of the current position.
*/

detached: function () {
this._clearWatch(watch_);
},

/**
* Stop updating latitude/longitude as the device changes position.
* @param {Number} watch watch ID value.
*/
_clearWatch: function (watch) {
if (watch !== null) {
navigator.geolocation.clearWatch(watch);
watch_ = null;
}
},

clear: function () {
this._setPosition(null);
this._setLatitude(null);
this._setLongitude(null);
},

fetch: function () {
if (watch_) {
navigator.geolocation.clearWatch(watch_);
watch_ = null;
}
this._clearWatch(watch_);

if (this.idle) {
return;
Expand All @@ -168,8 +180,7 @@

if (this.watchPos) {
watch_ = navigator.geolocation.watchPosition(success, error, options);
}
else {
} else {
navigator.geolocation.getCurrentPosition(success, error, options);
}
},
Expand Down

0 comments on commit 9eee56a

Please sign in to comment.