├── .gitignore ├── LICENSE.md ├── README.md ├── README_RU.md ├── dist ├── geolocate.js └── geolocate.min.js ├── gulpfile.js ├── index.html ├── index.js ├── package.json └── src └── geolocate.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 2GIS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mock-geolocation 2 | Mock for ```navigator.geolocation```. 3 | 4 | ### [Russian readme](https://github.com/2gis/mock-geolocation/blob/master/README_RU.md) ### 5 | 6 | ### [Demo](http://2gis.github.io/mock-geolocation/) ### 7 | 8 | ```javascript 9 | var point = [54.980206086231, 82.898068362003]; 10 | 11 | geolocate.use(); 12 | 13 | navigator.geolocation.getCurrentPosition(function(position) { 14 | assert(position.coords.latitude).equal(point[0]); 15 | assert(position.coords.longitude).equal(point[1]); 16 | }); 17 | 18 | geolocate.send({lat: point[0], lng: point[1]}); 19 | 20 | geolocate.restore(); 21 | ``` 22 | ## Installation 23 | Manually: 24 | ```html 25 | 26 | ``` 27 | From ```npm```: 28 | ``` 29 | npm install mock-geolocation 30 | ``` 31 | As ```CommonJS``` or ```AMD``` module: 32 | ```javascript 33 | var geolocate = require('mock-geolocation'); 34 | ``` 35 | ## API 36 | ### .use() 37 | Replace the native ```navigator.geolocation``` object 38 | ### .restore() 39 | Restore ```navigator.geolocation``` in original state 40 | ### .send([options]) 41 | This method emulates the finding position after calling [getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation.getCurrentPosition) and [watchPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation.watchPosition) method. 42 | Updates position from ```options``` which may include the following parameters from [positions.coords](https://developer.mozilla.org/en-US/docs/Web/API/Coordinates) and [timestamp](https://developer.mozilla.org/en-US/docs/Web/API/Position.timestamp). 43 | ```javascript 44 | navigator.geolocation.getCurrentPosition(function(position) { 45 | console.log(position); 46 | }); 47 | 48 | geolocate.send({ 49 | latitude: 50, 50 | longitude: 10, 51 | accuracy: 5, 52 | timestamp: 3000 53 | }); 54 | 55 | /* { 56 | coords: { 57 | accuracy: 5, 58 | altitude: null 59 | altitudeAccuracy: null, 60 | heading: null, 61 | latitude: 50 62 | longitude: 10, 63 | speed: null 64 | }, 65 | timestamp: 3000 66 | } */ 67 | 68 | navigator.geolocation.getCurrentPosition(function(position) { 69 | console.log(position); 70 | }); 71 | 72 | geolocate.send(); 73 | 74 | /* Show same position { 75 | coords: { 76 | accuracy: 5, 77 | altitude: null 78 | altitudeAccuracy: null, 79 | heading: null, 80 | latitude: 50 81 | longitude: 10, 82 | speed: null 83 | }, 84 | timestamp: 3000 85 | } */ 86 | ``` 87 | ### .change(options) 88 | Change current position and call ```success callback``` of ```watchPosition``` method. 89 | Updates position from ```options``` which may include the following parameters from [positions.coords](https://developer.mozilla.org/en-US/docs/Web/API/Coordinates) and [timestamp](https://developer.mozilla.org/en-US/docs/Web/API/Position.timestamp). 90 | ```javascript 91 | navigator.geolocation.watchPosition(function(position) { 92 | console.log(position.coords.latitude + ', ' + position.coords.longitude); 93 | }); 94 | 95 | geolocate.send(); 96 | // 54.9799, 82.89683699999999 97 | 98 | geolocate.change({lat: 10, lng: 15}); 99 | // 10, 15 100 | 101 | geolocate.change({lat: 25}); 102 | // 25, 15 103 | ``` 104 | ### .sendError([options]) 105 | Call ```error callback``` of ```getCurrentPosition``` method. 106 | ```options``` may include the parameters [code and message](https://developer.mozilla.org/en-US/docs/Web/API/PositionError). 107 | ### .changeError([options]) 108 | Call ```error callback``` of ```watchPosition``` method. 109 | ```options``` may include the parameters [code and message](https://developer.mozilla.org/en-US/docs/Web/API/PositionError). 110 | -------------------------------------------------------------------------------- /README_RU.md: -------------------------------------------------------------------------------- 1 | # Mock-geolocation 2 | Мок для ```navigator.geolocation```. 3 | Модуль подменяет стандартную геолокацию браузера. 4 | 5 | ### [English readme](https://github.com/2gis/mock-geolocation/blob/master/README.md) ### 6 | 7 | ### [Demo](http://2gis.github.io/mock-geolocation/) ### 8 | 9 | ```javascript 10 | var point = [54.980206086231, 82.898068362003]; 11 | 12 | geolocate.use(); 13 | 14 | navigator.geolocation.getCurrentPosition(function(position) { 15 | assert(position.coords.latitude).equal(point[0]); 16 | assert(position.coords.longitude).equal(point[1]); 17 | }); 18 | 19 | geolocate.send({lat: point[0], lng: point[1]}); 20 | 21 | geolocate.restore(); 22 | ``` 23 | ## Установка 24 | Вручную: 25 | ```html 26 | 27 | ``` 28 | Из ```npm```: 29 | ``` 30 | npm install mock-geolocation 31 | ``` 32 | Как ```CommonJS``` или ```AMD``` модуль: 33 | ```javascript 34 | var geolocate = require('mock-geolocation'); 35 | ``` 36 | ## API 37 | ### .use() 38 | Заменяет объект ```navigator.geolocation``` 39 | ### .restore() 40 | Возвращает ```navigator.geolocation``` в исходное состояние 41 | ### .send([options]) 42 | Имитирует нахождение позиции после вызова метода [getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation.getCurrentPosition) и [watchPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation.watchPosition). 43 | Обновляет текущую позицию из ```options```, в которых могут задаваться все параметры [positions.coords](https://developer.mozilla.org/en-US/docs/Web/API/Coordinates) и [timestamp](https://developer.mozilla.org/en-US/docs/Web/API/Position.timestamp). 44 | ```javascript 45 | navigator.geolocation.getCurrentPosition(function(position) { 46 | console.log(position); 47 | }); 48 | 49 | geolocate.send({ 50 | latitude: 50, 51 | longitude: 10, 52 | accuracy: 5, 53 | timestamp: 3000 54 | }); 55 | 56 | /* { 57 | coords: { 58 | accuracy: 5, 59 | altitude: null 60 | altitudeAccuracy: null, 61 | heading: null, 62 | latitude: 50 63 | longitude: 10, 64 | speed: null 65 | }, 66 | timestamp: 3000 67 | } */ 68 | 69 | navigator.geolocation.getCurrentPosition(function(position) { 70 | console.log(position); 71 | }); 72 | 73 | geolocate.send(); 74 | 75 | /* Выведит такую же позицию { 76 | coords: { 77 | accuracy: 5, 78 | altitude: null 79 | altitudeAccuracy: null, 80 | heading: null, 81 | latitude: 50 82 | longitude: 10, 83 | speed: null 84 | }, 85 | timestamp: 3000 86 | } */ 87 | ``` 88 | ### .change(options) 89 | Меняет текущую позицию и вызывает ```success callback``` метода ```watchPosition```. 90 | Обновляет текущую позицию из ```options```, в которых могут задаваться все параметры [positions.coords](https://developer.mozilla.org/en-US/docs/Web/API/Coordinates) и [timestamp](https://developer.mozilla.org/en-US/docs/Web/API/Position.timestamp). 91 | ```javascript 92 | navigator.geolocation.watchPosition(function(position) { 93 | console.log(position.coords.latitude + ', ' + position.coords.longitude); 94 | }); 95 | 96 | geolocate.send(); 97 | // 54.9799, 82.89683699999999 98 | 99 | geolocate.change({lat: 10, lng: 15}); 100 | // 10, 15 101 | 102 | geolocate.change({lat: 25}); 103 | // 25, 15 104 | ``` 105 | ### .sendError([options]) 106 | Вызывает ```error callback``` метода ```getCurrentPosition```. 107 | В ```options``` задаются параметры [code и message](https://developer.mozilla.org/en-US/docs/Web/API/PositionError). 108 | ### .changeError([options]) 109 | Вызывает ```error callback``` метода ```watchPosition```. 110 | В ```options``` задаются параметры [code и message](https://developer.mozilla.org/en-US/docs/Web/API/PositionError). 111 | -------------------------------------------------------------------------------- /dist/geolocate.js: -------------------------------------------------------------------------------- 1 | (function(window, navigator) { 2 | var exports = {}, 3 | counterId = 0, 4 | successData = { 5 | accuracy: 50, 6 | altitude: null, 7 | altitudeAccuracy: null, 8 | heading: null, 9 | latitude: 54.9799, 10 | longitude: 82.89683699999999, 11 | speed: null 12 | }, 13 | errorData = { 14 | code: 1, 15 | message: 'The acquisition of the geolocation information failed because the page didn\'t have the permission to do it.' 16 | }; 17 | 18 | var getCurrentPositionArguments = {}, 19 | watchPositionArguments = {}, 20 | _navigatorGeolocation; 21 | 22 | var changeGeolocation = function(object) { 23 | if (Object.defineProperty) { 24 | Object.defineProperty(navigator, 'geolocation', { 25 | get: function() { 26 | return object; 27 | }, 28 | configurable: true 29 | }); 30 | } else if (navigator.__defineGetter__) { 31 | navigator.__defineGetter__('geolocation', function() { 32 | return object; 33 | }); 34 | } else { 35 | throw new Error('Cannot change navigator.geolocation method'); 36 | } 37 | }; 38 | 39 | exports.use = function() { 40 | _navigatorGeolocation = navigator.geolocation; 41 | 42 | changeGeolocation({ 43 | getCurrentPosition: function(success, error, opt) { 44 | counterId++; 45 | getCurrentPositionArguments[counterId] = arguments; 46 | }, 47 | watchPosition: function(success, error, opt) { 48 | counterId++; 49 | getCurrentPositionArguments[counterId] = arguments; 50 | watchPositionArguments[counterId] = arguments; 51 | return counterId; 52 | }, 53 | clearWatch: function(i) { 54 | if (watchPositionArguments[i]) { 55 | delete watchPositionArguments[i]; 56 | 57 | if (getCurrentPositionArguments[i]) { 58 | delete getCurrentPositionArguments[i]; 59 | } 60 | } 61 | } 62 | }); 63 | 64 | return this; 65 | }; 66 | 67 | exports.restore = function() { 68 | if (_navigatorGeolocation) { 69 | changeGeolocation(_navigatorGeolocation); 70 | } else { 71 | delete navigator.geolocation; 72 | } 73 | 74 | getCurrentPositionArguments = {}; 75 | watchPositionArguments = {}; 76 | 77 | return this; 78 | }; 79 | 80 | function changeSuccessData(options) { 81 | // copy available parameter to successData 82 | for (var i in successData) { 83 | if (options.hasOwnProperty(i)) { 84 | successData[i] = options[i]; 85 | } 86 | } 87 | 88 | // lat and lng are available parameters too 89 | if (options.lat !== undefined) { 90 | successData.latitude = options.lat; 91 | } 92 | if (options.lng !== undefined) { 93 | successData.longitude = options.lng; 94 | } 95 | } 96 | 97 | function getRequestData(options) { 98 | options = options || {}; 99 | 100 | var data = { 101 | coords: {} 102 | }; 103 | 104 | for (var i in successData) { 105 | data.coords[i] = successData[i]; 106 | } 107 | 108 | if (options.timestamp !== undefined) { 109 | data.timestamp = options.timestamp; 110 | } else { 111 | data.timestamp = Date.now(); 112 | } 113 | 114 | return data; 115 | } 116 | 117 | function getErrorData(options) { 118 | options = options || {}; 119 | 120 | var data = {}; 121 | 122 | if (options.code !== undefined) { 123 | data.code = options.code; 124 | } else { 125 | data.code = errorData.code; 126 | } 127 | 128 | if (options.message !== undefined) { 129 | data.message = options.message; 130 | } else { 131 | data.message = errorData.message; 132 | } 133 | 134 | return data; 135 | } 136 | 137 | exports.send = function(options) { 138 | if (options) { 139 | changeSuccessData(options); 140 | } 141 | 142 | for (var i in getCurrentPositionArguments) { 143 | if (typeof getCurrentPositionArguments[i][0] === 'function') { 144 | getCurrentPositionArguments[i][0](getRequestData(options)); 145 | } 146 | } 147 | 148 | getCurrentPositionArguments = {}; 149 | 150 | return this; 151 | }; 152 | 153 | exports.sendError = function(options) { 154 | for (var i in getCurrentPositionArguments) { 155 | if (typeof getCurrentPositionArguments[i][1] === 'function') { 156 | getCurrentPositionArguments[i][1](getErrorData(options)); 157 | } 158 | } 159 | 160 | getCurrentPositionArguments = {}; 161 | 162 | return this; 163 | }; 164 | 165 | exports.change = function(options) { 166 | if (options) { 167 | changeSuccessData(options); 168 | } 169 | 170 | for (var i in watchPositionArguments) { 171 | if (typeof watchPositionArguments[i][0] === 'function') { 172 | watchPositionArguments[i][0](getRequestData(options)); 173 | } 174 | 175 | if (getCurrentPositionArguments[i]) { 176 | delete getCurrentPositionArguments[i]; 177 | } 178 | } 179 | 180 | return this; 181 | }; 182 | 183 | exports.changeError = function(options) { 184 | for (var i in watchPositionArguments) { 185 | if (typeof watchPositionArguments[i][1] === 'function') { 186 | watchPositionArguments[i][1](getErrorData(options)); 187 | } 188 | 189 | if (getCurrentPositionArguments[i]) { 190 | delete getCurrentPositionArguments[i]; 191 | } 192 | } 193 | 194 | return this; 195 | }; 196 | 197 | function expose() { 198 | var _geolocate = window.geolocate; 199 | 200 | exports.noConflict = function() { 201 | if (_geolocate !== undefined) { 202 | window.geolocate = _geolocate; 203 | } else { 204 | delete window.geolocate; 205 | } 206 | 207 | return exports; 208 | }; 209 | 210 | window.geolocate = exports; 211 | } 212 | 213 | // define for Node module pattern loaders, including Browserify 214 | if (typeof module === 'object' && typeof module.exports === 'object') { 215 | module.exports = exports; 216 | 217 | // define as an AMD module 218 | } else if (typeof define === 'function' && define.amd) { 219 | define(exports); 220 | 221 | // define as a global variable, saving the original to restore later if needed 222 | } else if (typeof window !== 'undefined') { 223 | expose(); 224 | } 225 | })(window, navigator); 226 | -------------------------------------------------------------------------------- /dist/geolocate.min.js: -------------------------------------------------------------------------------- 1 | !function(e,t){function o(e){for(var t in f)e.hasOwnProperty(t)&&(f[t]=e[t]);void 0!==e.lat&&(f.latitude=e.lat),void 0!==e.lng&&(f.longitude=e.lng)}function n(e){e=e||{};var t={coords:{}};for(var o in f)t.coords[o]=f[o];return void 0!==e.timestamp?t.timestamp=e.timestamp:t.timestamp=Date.now(),t}function i(e){e=e||{};var t={};return void 0!==e.code?t.code=e.code:t.code=d.code,void 0!==e.message?t.message=e.message:t.message=d.message,t}function r(){var t=e.geolocate;c.noConflict=function(){return void 0!==t?e.geolocate=t:delete e.geolocate,c},e.geolocate=c}var a,c={},u=0,f={accuracy:50,altitude:null,altitudeAccuracy:null,heading:null,latitude:54.9799,longitude:82.89683699999999,speed:null},d={code:1,message:"The acquisition of the geolocation information failed because the page didn't have the permission to do it."},l={},s={},g=function(e){if(Object.defineProperty)Object.defineProperty(t,"geolocation",{get:function(){return e},configurable:!0});else{if(!t.__defineGetter__)throw new Error("Cannot change navigator.geolocation method");t.__defineGetter__("geolocation",function(){return e})}};c.use=function(){return a=t.geolocation,g({getCurrentPosition:function(e,t,o){u++,l[u]=arguments},watchPosition:function(e,t,o){return u++,l[u]=arguments,s[u]=arguments,u},clearWatch:function(e){s[e]&&(delete s[e],l[e]&&delete l[e])}}),this},c.restore=function(){return a?g(a):delete t.geolocation,l={},s={},this},c.send=function(e){e&&o(e);for(var t in l)"function"==typeof l[t][0]&&l[t][0](n(e));return l={},this},c.sendError=function(e){for(var t in l)"function"==typeof l[t][1]&&l[t][1](i(e));return l={},this},c.change=function(e){e&&o(e);for(var t in s)"function"==typeof s[t][0]&&s[t][0](n(e)),l[t]&&delete l[t];return this},c.changeError=function(e){for(var t in s)"function"==typeof s[t][1]&&s[t][1](i(e)),l[t]&&delete l[t];return this},"object"==typeof module&&"object"==typeof module.exports?module.exports=c:"function"==typeof define&&define.amd?define(c):"undefined"!=typeof e&&r()}(window,navigator); -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | uglify = require('gulp-uglify'), 3 | rename = require('gulp-rename'); 4 | 5 | gulp.task('uglify', function() { 6 | return gulp.src('src/geolocate.js') 7 | .pipe(uglify()) 8 | .pipe(rename('geolocate.min.js')) 9 | .pipe(gulp.dest('dist')); 10 | }); 11 | 12 | gulp.task('copy', function() { 13 | return gulp.src('src/geolocate.js') 14 | .pipe(gulp.dest('dist')); 15 | }) 16 | 17 | gulp.task('default', ['uglify', 'copy']); 18 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
25 | geolocate.use();
26 |
27 |
31 | geolocate.restore();
32 |
33 |
44 | geolocate.send({lat: 54.9805, lng: 82.8985});
45 |
46 |
50 | geolocate.change({lat: 54.9810, lng: 82.8990});
51 |
52 |
56 | geolocate.change({lat: 54.9810, lng: 82.8995});
57 |
58 |
62 | geolocate.change({lat: 54.9815, lng: 82.9005});
63 |
64 |
68 |
69 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./src/geolocate.js');
2 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mock-geolocation",
3 | "version": "1.0.11",
4 | "description": "Mock for navigator.geolocation API",
5 | "author": {
6 | "name": "Mstislav Zhivodkov",
7 | "email": "stevemyz@gmail.com"
8 | },
9 | "license": "MIT",
10 | "keywords": [
11 | "geolocation",
12 | "mock"
13 | ],
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/2gis/mock-geolocation.git"
17 | },
18 | "dependencies": {},
19 | "devDependencies": {
20 | "gulp": "^3.8.11",
21 | "gulp-uglify": "^1.1.0",
22 | "gulp-rename": "^1.2.0"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/geolocate.js:
--------------------------------------------------------------------------------
1 | (function(window, navigator) {
2 | var exports = {},
3 | counterId = 0,
4 | successData = {
5 | accuracy: 50,
6 | altitude: null,
7 | altitudeAccuracy: null,
8 | heading: null,
9 | latitude: 54.9799,
10 | longitude: 82.89683699999999,
11 | speed: null
12 | },
13 | errorData = {
14 | code: 1,
15 | message: 'The acquisition of the geolocation information failed because the page didn\'t have the permission to do it.'
16 | };
17 |
18 | var getCurrentPositionArguments = {},
19 | watchPositionArguments = {},
20 | _navigatorGeolocation;
21 |
22 | var changeGeolocation = function(object) {
23 | if (Object.defineProperty) {
24 | Object.defineProperty(navigator, 'geolocation', {
25 | get: function() {
26 | return object;
27 | },
28 | configurable: true
29 | });
30 | } else if (navigator.__defineGetter__) {
31 | navigator.__defineGetter__('geolocation', function() {
32 | return object;
33 | });
34 | } else {
35 | throw new Error('Cannot change navigator.geolocation method');
36 | }
37 | };
38 |
39 | exports.use = function() {
40 | _navigatorGeolocation = navigator.geolocation;
41 |
42 | changeGeolocation({
43 | getCurrentPosition: function(success, error, opt) {
44 | counterId++;
45 | getCurrentPositionArguments[counterId] = arguments;
46 | },
47 | watchPosition: function(success, error, opt) {
48 | counterId++;
49 | getCurrentPositionArguments[counterId] = arguments;
50 | watchPositionArguments[counterId] = arguments;
51 | return counterId;
52 | },
53 | clearWatch: function(i) {
54 | if (watchPositionArguments[i]) {
55 | delete watchPositionArguments[i];
56 |
57 | if (getCurrentPositionArguments[i]) {
58 | delete getCurrentPositionArguments[i];
59 | }
60 | }
61 | }
62 | });
63 |
64 | return this;
65 | };
66 |
67 | exports.restore = function() {
68 | if (_navigatorGeolocation) {
69 | changeGeolocation(_navigatorGeolocation);
70 | } else {
71 | delete navigator.geolocation;
72 | }
73 |
74 | getCurrentPositionArguments = {};
75 | watchPositionArguments = {};
76 |
77 | return this;
78 | };
79 |
80 | function changeSuccessData(options) {
81 | // copy available parameter to successData
82 | for (var i in successData) {
83 | if (options.hasOwnProperty(i)) {
84 | successData[i] = options[i];
85 | }
86 | }
87 |
88 | // lat and lng are available parameters too
89 | if (options.lat !== undefined) {
90 | successData.latitude = options.lat;
91 | }
92 | if (options.lng !== undefined) {
93 | successData.longitude = options.lng;
94 | }
95 | }
96 |
97 | function getRequestData(options) {
98 | options = options || {};
99 |
100 | var data = {
101 | coords: {}
102 | };
103 |
104 | for (var i in successData) {
105 | data.coords[i] = successData[i];
106 | }
107 |
108 | if (options.timestamp !== undefined) {
109 | data.timestamp = options.timestamp;
110 | } else {
111 | data.timestamp = Date.now();
112 | }
113 |
114 | return data;
115 | }
116 |
117 | function getErrorData(options) {
118 | options = options || {};
119 |
120 | var data = {};
121 |
122 | if (options.code !== undefined) {
123 | data.code = options.code;
124 | } else {
125 | data.code = errorData.code;
126 | }
127 |
128 | if (options.message !== undefined) {
129 | data.message = options.message;
130 | } else {
131 | data.message = errorData.message;
132 | }
133 |
134 | return data;
135 | }
136 |
137 | exports.send = function(options) {
138 | if (options) {
139 | changeSuccessData(options);
140 | }
141 |
142 | for (var i in getCurrentPositionArguments) {
143 | if (typeof getCurrentPositionArguments[i][0] === 'function') {
144 | getCurrentPositionArguments[i][0](getRequestData(options));
145 | }
146 | }
147 |
148 | getCurrentPositionArguments = {};
149 |
150 | return this;
151 | };
152 |
153 | exports.sendError = function(options) {
154 | for (var i in getCurrentPositionArguments) {
155 | if (typeof getCurrentPositionArguments[i][1] === 'function') {
156 | getCurrentPositionArguments[i][1](getErrorData(options));
157 | }
158 | }
159 |
160 | getCurrentPositionArguments = {};
161 |
162 | return this;
163 | };
164 |
165 | exports.change = function(options) {
166 | if (options) {
167 | changeSuccessData(options);
168 | }
169 |
170 | for (var i in watchPositionArguments) {
171 | if (typeof watchPositionArguments[i][0] === 'function') {
172 | watchPositionArguments[i][0](getRequestData(options));
173 | }
174 |
175 | if (getCurrentPositionArguments[i]) {
176 | delete getCurrentPositionArguments[i];
177 | }
178 | }
179 |
180 | return this;
181 | };
182 |
183 | exports.changeError = function(options) {
184 | for (var i in watchPositionArguments) {
185 | if (typeof watchPositionArguments[i][1] === 'function') {
186 | watchPositionArguments[i][1](getErrorData(options));
187 | }
188 |
189 | if (getCurrentPositionArguments[i]) {
190 | delete getCurrentPositionArguments[i];
191 | }
192 | }
193 |
194 | return this;
195 | };
196 |
197 | function expose() {
198 | var _geolocate = window.geolocate;
199 |
200 | exports.noConflict = function() {
201 | if (_geolocate !== undefined) {
202 | window.geolocate = _geolocate;
203 | } else {
204 | delete window.geolocate;
205 | }
206 |
207 | return exports;
208 | };
209 |
210 | window.geolocate = exports;
211 | }
212 |
213 | // define for Node module pattern loaders, including Browserify
214 | if (typeof module === 'object' && typeof module.exports === 'object') {
215 | module.exports = exports;
216 |
217 | // define as an AMD module
218 | } else if (typeof define === 'function' && define.amd) {
219 | define(exports);
220 |
221 | // define as a global variable, saving the original to restore later if needed
222 | } else if (typeof window !== 'undefined') {
223 | expose();
224 | }
225 | })(window, navigator);
226 |
--------------------------------------------------------------------------------