这是我的代码段
function getDistance(){
var origins = ['San Francisco CA'];
var destinations = ['New York NY'];
distance.matrix(origins, destinations, function (err, distances) {
if (distances.status == 'OK') {
var origin = distances.origin_addresses[0];
var destination = distances.destination_addresses[0];
if (distances.rows[0].elements[0].status == 'OK') {
var distance = distances.rows[0].elements[0].distance.text;
return distance;
}else{
return 0;
}
} else{return 0;}
});
我想在调用getDistance()函数时返回距离值
我该怎么做?