2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
2011-07-06 15:30:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @fileoverview Atom to retrieve the physical location of the device.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
goog.provide('bot.geolocation');
|
|
|
|
|
|
|
|
|
|
goog.require('bot');
|
|
|
|
|
goog.require('bot.html5');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default parameters used to configure the geolocation.getCurrentPosition
|
|
|
|
|
* method. These parameters mean retrieval of any cached position with high
|
|
|
|
|
* accuracy within a timeout interval of 5s.
|
|
|
|
|
* @const
|
2019-09-17 10:22:56 +01:00
|
|
|
* @type {!GeolocationPositionOptions}
|
2011-07-06 15:30:00 +00:00
|
|
|
* @see http://dev.w3.org/geo/api/spec-source.html#position-options
|
|
|
|
|
*/
|
2019-09-17 10:22:56 +01:00
|
|
|
bot.geolocation.DEFAULT_OPTIONS = /** @type {!GeolocationPositionOptions} */ ({
|
2011-07-06 15:30:00 +00:00
|
|
|
enableHighAccuracy: true,
|
|
|
|
|
maximumAge: Infinity,
|
|
|
|
|
timeout: 5000
|
2013-03-10 13:29:08 -07:00
|
|
|
});
|
2011-07-06 15:30:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides a mechanism to retrieve the geolocation of the device. It invokes
|
|
|
|
|
* the navigator.geolocation.getCurrentPosition method of the HTML5 API which
|
|
|
|
|
* later callbacks with either position value or any error. The position/
|
|
|
|
|
* error is updated with the callback functions.
|
2011-08-26 22:18:36 +00:00
|
|
|
*
|
|
|
|
|
* @param {function(?GeolocationPosition)} successCallback The callback method
|
|
|
|
|
* which is invoked on success.
|
2019-09-17 10:22:56 +01:00
|
|
|
* @param {function(?GeolocationPositionError)=} opt_errorCallback The callback
|
2011-08-26 22:18:36 +00:00
|
|
|
* method which is invoked on error.
|
2019-09-17 10:22:56 +01:00
|
|
|
* @param {?GeolocationPositionOptions=} opt_options The optional parameters to
|
2011-07-06 15:30:00 +00:00
|
|
|
* navigator.geolocation.getCurrentPosition; defaults to
|
|
|
|
|
* bot.geolocation.DEFAULT_OPTIONS.
|
|
|
|
|
*/
|
2011-08-26 22:18:36 +00:00
|
|
|
bot.geolocation.getCurrentPosition = function(successCallback,
|
|
|
|
|
opt_errorCallback, opt_options) {
|
2011-07-06 15:30:00 +00:00
|
|
|
var win = bot.getWindow();
|
|
|
|
|
var posOptions = opt_options || bot.geolocation.DEFAULT_OPTIONS;
|
|
|
|
|
|
|
|
|
|
if (bot.html5.isSupported(bot.html5.API.GEOLOCATION, win)) {
|
|
|
|
|
var geolocation = win.navigator.geolocation;
|
2011-08-26 22:18:36 +00:00
|
|
|
geolocation.getCurrentPosition(successCallback,
|
|
|
|
|
opt_errorCallback, posOptions);
|
2011-07-06 15:30:00 +00:00
|
|
|
} else {
|
|
|
|
|
throw new bot.Error(bot.ErrorCode.UNKNOWN_ERROR, 'Geolocation undefined');
|
|
|
|
|
}
|
|
|
|
|
};
|