我想使用谷歌的api矩陣的距離從兩個地址檢索儀表,但回調函數永遠不會被調用。也許範圍問題?回調api谷歌
prove: function(){
var origin = new google.maps.LatLng(50.087, 40.087);
var destination= new google.maps.LatLng(38, 39);
function calculateDistances() {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
}, callback); <--netbeans tell me callback is not declared
}
function callback(response, status) {
console.log("incallback"); <---never called
}
}
只是一個評論,將更容易,如果你格式化你的代碼 – user1477388
完成,格式化.. –
你沒有傳遞任何參數到你的回調,爲一。看到這個更多的信息http://stackoverflow.com/questions/14061990/javascript-pass-parameter-to-callback-or-set-variable-value-in-distancematrixsta – user1477388