Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript异步函数调用:在回调函数中检索调用函数参数_Javascript_Google Maps - Fatal编程技术网

Javascript异步函数调用:在回调函数中检索调用函数参数

Javascript异步函数调用:在回调函数中检索调用函数参数,javascript,google-maps,Javascript,Google Maps,如何在Javascript回调函数中获取用户状态?就像我有一个Javascript函数进行异步调用一样,如下所示。现在在回调函数中,我需要访问userstate。我该怎么做?在Silverlight中,我们有用户状态之类的东西。我们在Javascript中也有同样的机制吗。请帮忙 注意:我不想使用全局变量,因为Func1()将在For循环中执行 function Func1() { var userState = "someValue"; geocoder.as

如何在Javascript回调函数中获取用户状态?就像我有一个Javascript函数进行异步调用一样,如下所示。现在在回调函数中,我需要访问userstate。我该怎么做?在Silverlight中,我们有用户状态之类的东西。我们在Javascript中也有同样的机制吗。请帮忙

注意:我不想使用全局变量,因为Func1()将在For循环中执行

   function Func1() {
       var userState = "someValue";
       geocoder.asyncCall(parameters , CallBack);
   }


   function CallBack(result) {

       // Use result
       // How to access userState in this function
   }
请尝试以下代码:

function Func1() {
   var userState = "someValue";
   geocoder.asyncCall(parameters ,function(){ 
      CallBack(userState);
   });
}


function CallBack(result) {

   // Use result
   // How to access userState in this function
}
更新

function PlotAddressOnMap(address) { 
   var address = address; 
   var userState="userState";
   geocoder.geocode({ 'address': address }, CityDetailsReceived(userState)); 
} 

function CityDetailsReceived(userState) {
   return function(results, status){
      //your code
   }
} 

虽然我得到了userState,但是我现在没有得到预期的结果。实际上,我正在使用GoogleAPI,如下所示://函数使用GoogleGeocoder函数PlotAddressOnMap(address){var address=address;var userState=“userState”;Geocoder.geocode({‘address’:address},CallBack(userState));}函数CityDetailsReceived(用户状态、结果、状态){}虽然我现在可以获取userState,但我没有在结果和状态变量中获得预期结果。虽然我获取userState,但我现在没有获得预期结果。实际上我正在使用Google API,如下所示://函数使用Google Geocoder函数PlotAddressOnMap(address)获取状态详细信息{var address=address;var userState=“userState”;geocoder.geocode({‘address’:address},CallBack(userState));}函数citydeailsreceived(userState,results,status){}虽然我现在可以获得userState,但在results和status变量中没有得到预期的结果。
function Func1() {
   var userState = "someValue";
   geocoder.asyncCall(parameters , CallBack(userState));
}


function CallBack(userState) {
   return function(result){
       // userState is accessible
   }
}