【发布时间】:2014-06-30 18:53:33
【问题描述】:
我正在使用 Google API 的 DistanceMatrixService 我试图在调用 getDistanceMatrix 函数时传递变量 'resto',这样当我得到响应时,我可以进一步使用该变量。 我的函数如下所示:
var service = new google.maps.DistanceMatrixService();
var resto = listRestaurant[i];
service.getDistanceMatrix({
origins: [ new google.maps.LatLng(locationCurrent.coords.latitude, locationCurrent.coords.longitude) ] ,
destinations: [ resto.address ],
//Here i am trying to pass the variable 'resto'
},function ( response , status , resto ){
if (status != google.maps.DistanceMatrixStatus.OK) {
alert('Error was: ' + status);
} else {
if( response.rows[0].elements[0].distance !=null ){
//Further use variable
console.log( resto );
callGeocoder( resto );
}
}
});
但是日志返回'未定义变量'
我做错了什么?
【问题讨论】:
标签: javascript google-maps google-api