我很难在这个出租车费脚本中添加一些额外的内容。它工作正常,但问题是我想添加一个下拉列表或复选框,以便人们可以点击客户数量来计算票价。出租车的起步价将增加 50 美分,每公里增加 20 美分,如果客户乘坐小巴,则每分钟增加 15 美分。我搜索了stackoverflow,但找不到任何好的解决方案。第二件事是我希望人们通过表格向我发送他们的请求。有没有人可以解决这个问题?
这是代码:
//--------------Settings--------------------------------
var countrycode="nl"
var rateperkm=1.95;
var rateperminute=0.30;
var ratio=3.19;
var minimum_fare=3.19;
var currencysymbol="€";
var avoidHighways=false;
var avoidTolls=false;
var showsummary=false;
var showroutemap=true;
var apikey="";
//----------End Settings--------------------------------
function initialize()
{
var options = {componentRestrictions: {country: countrycode}};
var input = /** @type {HTMLInputElement} */(document.getElementById('inputfrom'));
var searchBoxfrom = new google.maps.places.Autocomplete(input,options);
var input = /** @type {HTMLInputElement} */(document.getElementById('inputto'));
var searchBoxto = new google.maps.places.Autocomplete(input,options);
}
function ftn_estimate()
{
if (document.getElementById('inputfrom').value!="" && document.getElementById('inputto').value!="")
{
var origin = document.getElementById('inputfrom').value;
var destination = document.getElementById('inputto').value;
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: avoidHighways,
avoidTolls: avoidTolls,
}, callback);
}
}
function callback(response, status) {
if (status != google.maps.DistanceMatrixStatus.OK) {
alert('Error was: ' + status);
} else {
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
for (var i = 0; i < origins.length; i++) {
var results = response.rows[i].elements;
for (var j = 0; j < results.length; j++) {
if(showsummary)
{
document.getElementById('summary').innerHTML=origins[i] + ' to ' + destinations[j] + ': ' + results[j].distance.text + ' in '+ results[j].duration.text;
document.getElementById('summary').innerHTML+="<br /><font color='red'>" + disclaimer + "</font>"
}
document.getElementById('distance').value=(results[j].distance.value/1000).toFixed(1);
document.getElementById('time').value=(results[j].duration.value/60).toFixed(1);
var calc_fare_dist=(results[j].distance.value/1000)*rateperkm;
var calc_fare_time=(results[j].duration.value/60)*rateperminute;
// Provided you want to add 0.35 per minute to the "per mile price"
var calc_fare = (calc_fare_dist + calc_fare_time)+ratio;
if (calc_fare<minimum_fare)
{
calc_fare=minimum_fare;
}
document.getElementById('fare').value=currencysymbol+calc_fare.toFixed(2);
}
}
if (showroutemap)
{
var origin = document.getElementById('inputfrom').value;
var destination = document.getElementById('inputto').value;
getpath(origin,destination);
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
function getpath(a,b) {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({
preserveViewport: true
});
directionsService.route({
origin: a,
destination:b,
travelMode: google.maps.TravelMode.DRIVING
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
// directionsDisplay.setDirections(response);
var polyline = new google.maps.Polyline({
path: [],
strokeColor: '#0000FF',
strokeWeight: 3
});
var legs = response.routes[0].legs;
for (i = 0; i < legs.length; i++) {
var steps = legs[i].steps;
for (j = 0; j < steps.length; j++) {
var nextSegment = steps[j].path;
for (k = 0; k < nextSegment.length; k++) {
polyline.getPath().push(nextSegment[k]);
}
}
}
do{
var newpath = [];
for (k = 0; k < polyline.getPath().length; k += 2) {
newpath.push(polyline.getPath().getAt(k));
}
polyline.setPath(newpath);
}
while (polyline.getPath().length>1000)
var path = polyline.getPath();
var encodeString = google.maps.geometry.encoding.encodePath(path);
document.getElementById('mapspan').innerHTML='<center><img src="https://maps.googleapis.com/maps/api/staticmap?size=400x400&path=weight:3%7Ccolor:red%7Cenc:'+encodeString+'&key='+apikey+'" /></center>';
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
</script>