看起来您的“开始”变量calcRoute()
具有非美国邮政编码。如果您将起点默认为有效的美国邮政编码,那么一切都应该有效。另外...calculateSum()
在您将文本输入到mileageCost
.
function calcRoute() {
alert("inside calcRoute()");
var distanceInput = document.getElementById("distance");
var MileageInput = document.getElementById("mileage");
var start = "15219";
var end = document.getElementById("end").value;
alert("destination: " + end);
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
distanceInput.value = Math.round(response.routes[0].legs[0].distance.value / 1609.344);
var mileageCost = Math.round(((response.routes[0].legs[0].distance.value / 1609.344)-100)+150);
if (mileageCost < 150) {
MileageInput.value = 'FREE';
} else
MileageInput.value = mileageCost;
calculateSum();
}
});
}