File tree Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff 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- }
You can’t perform that action at this time.
0 commit comments