From f189201ee04ce61f517167eb847c8262c2d5ea5c Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 26 Sep 2011 15:11:38 -0400 Subject: [PATCH] trying to make the code more robust to things like watchPosition erroring out when enableHighAccuracy is set to true. --- web-world/js-impl.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web-world/js-impl.js b/web-world/js-impl.js index c74c353..738424f 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -949,6 +949,7 @@ LocationEventSource.prototype = plt.baselib.heir(EventSource.prototype); LocationEventSource.prototype.onStart = function(fireEvent) { + var that = this; if (this.id === undefined) { var success = function(position) { if (position.hasOwnProperty && @@ -961,6 +962,14 @@ 'longitude' : Number(position.coords.longitude) })); } }; + // If we fail while trying to watch the position + // using high accuracy, switch over to the coarse one. + var onFailSwitchoverToCoerse = function() { + navigator.geolocation.clearWatch(that.id); + that.id = navigator.geolocation.watchPosition( + success, + fail); + }; var fail = function(err) { // Quiet failure }; @@ -968,7 +977,7 @@ navigator.geolocation.getCurrentPosition(success, fail); this.id = navigator.geolocation.watchPosition( success, - fail, + onFailSwitchoverToCoerse, { enableHighAccuracy : true }); } }