Thank you for replying. I vaguely remember learning promises in codecademy. Unfortunately, this returns an empty object. Based on your answer, I found another solution that works:
function getPosition() {
"use strict";
return new Promise(function(resolve, reject) {
var coordinates = {
lat: null,
lng: null,
}
function success (pos) {
coordinates.lat = pos.coords.latitude;
coordinates.lng = pos.coords.longitude;
resolve(coordinates);
}
function fail(error){
reject(error);
}
navigator.geolocation.getCurrentPosition(success, fail);
});
}
return getPosition()
In both cases, the Promise takes much longer to see the result than just using console.log in the getCurrentPosition function. Is that expected?
It worked in a quick test I made. If in your case it is returning an empty object try returning a new object constructed with the values from the position (like you are doing in your code)
I agree that the call to the geolocation api could have been inside the promise.
It looks like that both codes are equivalent, the only difference is that you are returning a Promise instead of awaiting the value
Just saw that @weweb-team added a “get user location” action for workflows! Awesome to see how fast they can make a change that saves everyone hours of fiddling around. Thank you