taxi-tarif-Berechnung mit Hilfe von php mit google distance matrix api v2
Ich will einen taxi-tarif-Berechnung in meiner website.
Habe ich folgende Anforderungen:
Wenn Google Distance Matrix-Berechnung zeigen die folgenden Kilometer Entfernung, die rate sollte so gehen:
- Von 0 -10km = $65 (Festpreis) + 11%
- 10km = $70 + 11%
- 15km = $80 + 11%
- 20km = $90 + 11%
- 25km = $100 + 11%
- 30km = $120 + 11%
- 30km oben = $4 /km
Legte ich rate als $2 pro km ab 10 km über bis zu 30km + $50 extra, das Ergebnis :
wenn taxi, wenn drived für
- 20km = 20km × $2 + $50 = $90 + 11%
- 21km = 21km × $2 + $50 = $92 + 11%
- 22 km = 22 km × $2 + $50 = $94 + 11% und so
aber ich weiß nicht, berechnen den Festpreis von $65, ist die Update-rate bei unter 10 km Entfernung und 120 US-Dollar-rate für die 30 km und 30 km über ie $4/km .
dem script, das ich verwendet für die Google Distance Matrix ist, um zu zeigen, $2/km + $50 fix : (ich habe nicht Hinzugefügt 11% in diesem Skript)
<script src="http://maps.google.com/maps?file=api&v=2&key=_MY_API_KEY"
type="text/javascript"></script>
<?php
$rate=2;
$extra=50;
?>
<script type="text/javascript">
var geocoder, location1, location2, gDir;
var map;
var gdir;
var geocoder = null;
var addressMarker;
var directionsPanel;
var directions;
function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function() {
var drivingDistanceMiles = gDir.getDistance().meters / 1000;
var drivingDistanceround =
Math.round(drivingDistanceMiles*100)/100;
var cost = ((drivingDistanceMiles * <?php echo $rate; ?>) + (<?php
echo $extra; ?>))
<?php echo $rate; ?>) + (<?php echo
$extra; ?>))
};
*/
var fare=cost;
var fare = Math.round(fare*100)/100;
document.getElementById('results').innerHTML = '<table
width="100%" style="border-collapse:collapse; padding-top:3px;"><tr><td rowspan="2"
width="35"><img src="images/rates.png"></td><td><strong>Distance: </strong>' +
drivingDistanceround + ' Kilemeters</td></tr><tr><td><strong>Estimated Cost:
</strong>$ ' + fare + '</td></tr></table>';
});
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(-33.722626, 150.810585), 10);
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDimrectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
}
}
function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress);
}
function showLocation() {
geocoder.getLocations(document.forms[0].from.value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the first
address");
}
else
{
location1 = {lat:
response.Placemark[0].Point.coordinates[1], lon:
response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(document.forms[0].to.value, function
(response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode
the second address");
}
else
{
location2 = {lat:
response.Placemark[0].Point.coordinates[1], lon:
response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
gDir.load('from: ' + location1.address + '
to: ' + location2.address);
}
});
}
});
///////////////////////////////////////////////////////////
var directionsPanel;
var directions;
directionsPanel = document.getElementById("route");
directions = new GDirections(map, directionsPanel);
directions.load("from: "+document.forms[0].from.value+" to:
"+document.forms[0].to.value);
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<table width="915" border="2" cellpadding="0" cellspacing="0" bordercolor="#FF9F0F"
style="border-collapse:collapse">
<tr>
<td bgcolor="#FFFF99" style="padding:10px;"><table width="905" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td><div id="map_canvas" style="width: 914px; height: 480px; border: solid 1px
#336699"></div></td>
</tr>
<tr>
<td><div id="form" style="width: 904px; text-align:center; border: solid 1px
#336699; background:#d1e1e4;">
<form action="#" onsubmit="document.getElementById('route').innerHTML='';
showLocation(); setDirections(this.from.value, this.to.value); return false;">
<p style="font-family:Tahoma; font-size:8pt;">From:
<input id="fromAddress" type="text" onblur="if(this.value=='')
this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)
this.value='';" value="Street Name City, State" maxlength="50" size="26" name="from"
style="font-family:Tahoma; font-size:8pt;" />
To:
<input id="toAddress" type="text" onblur="if(this.value=='')
this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)
this.value='';" value="Street Name City, State" maxlength="50" size="26" name="to"
style="font-family:Tahoma; font-size:8pt;"/>
<input class="submit" name="submit" type="submit" value="Calculate"
style="font-family:Tahoma; font-size:8pt;" />
</p>
<div id="results" style="font-family:Tahoma; font-size:8pt; text-align:left;
padding-left:5px; padding-bottom:5px;"></div>
<div id="route" style="font-family:Tahoma; font-size:8pt; text-align:left;
padding-left:5px; padding-bottom:5px;"></div>
</form>
</div></td>
</tr>
</table></td>
</tr>
</table>
</body>
InformationsquelleAutor cool nicq | 2012-09-19
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich würde gerne vorschlagen, dass Sie gehen für Google Maps API V3, hier ist mein Skript getestet, wie pro Ihre Anforderung, und wie pro Ihre früheren Skript, ich würde vorschlagen, Sie gehen für @Pierre-Francoys Brousse Skript für Tarife,
dein code ist in der obersten, Sie haben keine Ahnung, tun, machen es mit Meilen ?
InformationsquelleAutor roshan thapa
Wenn Ihre Frage, wie Sie zu einem Festpreis oder einer variierenden 'rate', warum Sie nicht einfach eine if/else oder eine switch/case Logik?
Auch, warum sind Sie injizieren von php, wenn dies getan werden könnte, in javascript?
Statt
Warum nicht einfach tun
InformationsquelleAutor Pierre-Francoys Brousseau