From a36145fc1ff4544aa867d2928c27fea7d9d2fd7a Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 7 Feb 2013 16:20:15 +0100 Subject: [PATCH] Check if the Geolocation API is supported --- src/ol/geolocation.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ol/geolocation.js b/src/ol/geolocation.js index eab663b2fa..b75aaaf38c 100644 --- a/src/ol/geolocation.js +++ b/src/ol/geolocation.js @@ -1,4 +1,5 @@ -// FIXME: handle errors ? +// FIXME handle geolocation not supported +// FIXME handle geolocation errors goog.provide('ol.Geolocation'); goog.provide('ol.GeolocationProperty'); @@ -36,18 +37,20 @@ ol.Geolocation = function(opt_positionOptions) { */ this.position_ = null; - goog.events.listen( - this, ol.Object.getChangedEventType(ol.GeolocationProperty.PROJECTION), - this.handleProjectionChanged_, false, this); + if (ol.Geolocation.isSupported) { + goog.events.listen( + this, ol.Object.getChangedEventType(ol.GeolocationProperty.PROJECTION), + this.handleProjectionChanged_, false, this); - /** - * @private - * @type {number} - */ - this.watchId_ = navigator.geolocation.watchPosition( - goog.bind(this.positionChange_, this), - goog.bind(this.positionError_, this), - opt_positionOptions); + /** + * @private + * @type {number} + */ + this.watchId_ = navigator.geolocation.watchPosition( + goog.bind(this.positionChange_, this), + goog.bind(this.positionError_, this), + opt_positionOptions); + } }; goog.inherits(ol.Geolocation, ol.Object);