我正在使用Google的免费Distance Matrix API来计算两个地址之间的里程。我从地址传入地址并返回里程但返回错误说参数计数异常错误。
function calculateMiles(from, to) {
$.ajax({
type: "GET",
url: "http://maps.googleapis.com/maps/api/distancematrix/json?origins=" + from + "&destinations=" + to + "&mode=driving&sensor=false&units=imperial"
}).done(function(response) {
var miles;
$.each(response.rows, function() {
$.each(this.elements, function() {
miles = this.distance.text;
return false;
});
return false;
});
$('#miles').val(miles);
}).fail(function(response) {
alert(response);
});
}