我試圖從一個回調函數返回一個值,並將其賦值給一個變量,雖然很努力去解決問題 - 任何幫助將非常感激....從回調函數得到一個價值
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;
}
謝謝疃,但是那基本上就是我已經在做(在回調調用和參數中顯式引用'coords') – user1325164 2012-04-10 22:02:58
getLocation函數是正確的,但調用不正確getLocation只是在執行'callback(coords)'時拋棄返回。 – 2012-04-10 22:18:54