my problem is that I want that my second function wait for the end of the exection of the first function, (i want the first point, before call the routing) but that seems not working. I'am quite new to coding with this, and i would appreciate any help and advise.
the code is :
async function waitForLoc(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
latUser = (position.coords.latitude) ;
lngUser = (position.coords.longitude);
var marker = L.marker([latUser, lngUser]).addTo(mymap);
})
}else console.log("geolocation does not work");
return 1;
}
waitForLoc();
lat = coordinates[1];
lng = coordinates[0];
async function f() {
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});
let result = await promise;
if(Route){
mymap.removeControl(Route);
}
Route = L.Routing.control({
waypoints: [
L.latLng(latUser, lngUser),
L.latLng(lat, lng)
],
routeWhileDragging: false
}).addTo(mymap);
mymap.closePopup();
}
f();