我正在尝试从回调函数返回一个值并将其分配给一个变量,尽管我正在努力解决它 - 任何帮助将不胜感激......
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;
}