trying to make the code more robust to things like watchPosition erroring out when enableHighAccuracy is set to true.

This commit is contained in:
Danny Yoo 2011-09-26 15:11:38 -04:00
parent 1635c0a5d2
commit f189201ee0

View File

@ -949,6 +949,7 @@
LocationEventSource.prototype = plt.baselib.heir(EventSource.prototype); LocationEventSource.prototype = plt.baselib.heir(EventSource.prototype);
LocationEventSource.prototype.onStart = function(fireEvent) { LocationEventSource.prototype.onStart = function(fireEvent) {
var that = this;
if (this.id === undefined) { if (this.id === undefined) {
var success = function(position) { var success = function(position) {
if (position.hasOwnProperty && if (position.hasOwnProperty &&
@ -961,6 +962,14 @@
'longitude' : Number(position.coords.longitude) })); '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) { var fail = function(err) {
// Quiet failure // Quiet failure
}; };
@ -968,7 +977,7 @@
navigator.geolocation.getCurrentPosition(success, fail); navigator.geolocation.getCurrentPosition(success, fail);
this.id = navigator.geolocation.watchPosition( this.id = navigator.geolocation.watchPosition(
success, success,
fail, onFailSwitchoverToCoerse,
{ enableHighAccuracy : true }); { enableHighAccuracy : true });
} }
} }