Ich versuche, einen Wert aus einer Callback-Funktion zurückzukehren und es zu einem Variablen zuweisen, obwohl es habe Schwierigkeiten heraus zu arbeiten - jede Hilfe wirklich geschätzt würde ....einen Wert aus einer Callback-Funktion bekommt
var latlng1;
function getLocation(){
navigator.geolocation.getCurrentPosition (function (position){
coords = position.coords.latitude + "," + position.coords.longitude;
callback();
})
}
//how can I assign the coords value from the callback to variable latlng1 with global scope?
getLocation (function(){
//alert(coords);
return coords;
})
// -----------
//I'm trying something like this....but no joy
latlng1 = getLocation (function(){
return coords;
}
Dank Tuan, aber das ist im Wesentlichen, was ich bereits mache (Balken referenziert explizit auf "coords" im Callback Call und Argument) – user1325164
Die 'getLocation' Funktion ist korrekt, aber der Aufruf ist nicht. getLocation verwirft nur die Rückgabe, wenn 'Callback (coords)'. –