Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/atoms/html5/location.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* @fileoverview Atom to retrieve the physical location of the device.
20
*
21
*/
22
23
goog.provide('bot.geolocation');
24
25
goog.require('bot');
26
goog.require('bot.html5');
27
28
29
/**
30
* Default parameters used to configure the geolocation.getCurrentPosition
31
* method. These parameters mean retrieval of any cached position with high
32
* accuracy within a timeout interval of 5s.
33
* @const
34
* @type {!GeolocationPositionOptions}
35
* @see http://dev.w3.org/geo/api/spec-source.html#position-options
36
*/
37
bot.geolocation.DEFAULT_OPTIONS = /** @type {!GeolocationPositionOptions} */ ({
38
enableHighAccuracy: true,
39
maximumAge: Infinity,
40
timeout: 5000
41
});
42
43
44
/**
45
* Provides a mechanism to retrieve the geolocation of the device. It invokes
46
* the navigator.geolocation.getCurrentPosition method of the HTML5 API which
47
* later callbacks with either position value or any error. The position/
48
* error is updated with the callback functions.
49
*
50
* @param {function(?GeolocationPosition)} successCallback The callback method
51
* which is invoked on success.
52
* @param {function(?GeolocationPositionError)=} opt_errorCallback The callback
53
* method which is invoked on error.
54
* @param {?GeolocationPositionOptions=} opt_options The optional parameters to
55
* navigator.geolocation.getCurrentPosition; defaults to
56
* bot.geolocation.DEFAULT_OPTIONS.
57
*/
58
bot.geolocation.getCurrentPosition = function(successCallback,
59
opt_errorCallback, opt_options) {
60
var win = bot.getWindow();
61
var posOptions = opt_options || bot.geolocation.DEFAULT_OPTIONS;
62
63
if (bot.html5.isSupported(bot.html5.API.GEOLOCATION, win)) {
64
var geolocation = win.navigator.geolocation;
65
geolocation.getCurrentPosition(successCallback,
66
opt_errorCallback, posOptions);
67
} else {
68
throw new bot.Error(bot.ErrorCode.UNKNOWN_ERROR, 'Geolocation undefined');
69
}
70
};
71
72