Skip to content

Commit af97157

Browse files
refactor
1 parent b477de8 commit af97157

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

geolocation/success.https.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
coordinates: {latitude, longitude, accuracy}
2929
});
3030

31-
const position = await getCurrentGeolocation();
31+
const positionPromise = new Promise(
32+
(resolve, reject) =>
33+
window.navigator.geolocation.getCurrentPosition(
34+
position => resolve(position.coords.toJSON()),
35+
error => reject(error),
36+
{timeout: 200}
37+
))
38+
const position = await positionPromise;
3239

3340
assert_equals(position.latitude, latitude);
3441
assert_equals(position.longitude, longitude);

geolocation/support.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,3 @@ var errorToString = function(err) {
2828
}
2929
return '[code: ' + codeString + ' (' + err.code + '), message: ' + (err.message ? err.message : '(empty)') + ']';
3030
};
31-
32-
/**
33-
* Returns the current geolocation or throws error.
34-
*
35-
* @param {number} timeout - Timeout in milliseconds, default is 200ms.
36-
*/
37-
function getCurrentGeolocation(timeout = 200) {
38-
return new Promise(
39-
(resolve, reject) => window.navigator.geolocation.getCurrentPosition(
40-
position => resolve(position.coords.toJSON()),
41-
error => reject(error),
42-
// Fail fast if geolocation is not available.
43-
{timeout}
44-
))
45-
}

0 commit comments

Comments
 (0)