0
我有一個小距離和持續時間計算器,我想知道我會如何繞上/下降我的最終數字,例如,而不是最終持續時間7.433333333333334分鐘或最終距離爲3.604公里。我會得到7分鐘和4公里。如何使Google地圖持續時間和距離計算器變圓
這裏是我當前的代碼:
<html>
\t <head>
\t \t <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
\t \t <title>Distance Calculator</title>
\t \t <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
\t \t <style type="text/css">
\t \t \t #map_canvas {
\t \t \t \t height: 50%;
\t \t \t \t width: 100%;
\t \t \t }
\t \t </style>
\t \t <script type="text/javascript">
\t \t var directionDisplay;
\t \t var directionsService = new google.maps.DirectionsService();
\t \t var map;
\t \t
\t \t
\t \t function initialize() {
\t \t \t directionsDisplay = new google.maps.DirectionsRenderer();
\t \t \t var perth = new google.maps.LatLng(-31.949766, 115.860928);
\t \t \t var myOptions = {
\t \t \t \t zoom:12,
\t \t \t \t mapTypeId: google.maps.MapTypeId.ROADMAP,
\t \t \t \t center: perth
\t \t \t }
\t \t \t map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
\t \t \t directionsDisplay.setMap(map);
\t \t }
\t \t function calcRoute() {
\t \t \t var start = document.getElementById("start").value;
\t \t \t var end = document.getElementById("end").value;
\t \t \t var distanceInput = document.getElementById("distance");
\t \t \t var durationInput = document.getElementById("duration");
\t \t \t
\t \t \t
\t \t \t var request = {
\t \t \t \t origin:start,
\t \t \t \t destination:end,
\t \t \t \t travelMode: google.maps.DirectionsTravelMode.DRIVING
\t \t \t };
\t \t \t
\t \t \t directionsService.route(request, function(response, status) {
\t \t \t \t if (status == google.maps.DirectionsStatus.OK) {
\t \t \t \t \t directionsDisplay.setDirections(response);
\t \t \t \t \t distanceInput.value = response.routes[0].legs[0].distance.value/1000;
\t \t \t \t \t durationInput.value = response.routes[0].legs[0].duration.value/60;
\t \t \t \t \t }
\t \t \t });
\t \t }
\t \t
\t \t function updateDue() {
var total = parseInt(document.getElementById("odoend").value);
var val2 = parseInt(document.getElementById("odostart").value);
var val3 = parseInt(document.getElementById("distance").value);
// to make sure that they are numbers
if (!total) { total = 0; }
if (!val2) { val2 = 0; }
if (!val3) { val3 = 0; }
var ansD = document.getElementById("kmused");
ansD.value = total - val2;
var ansE = document.getElementById("kmpriv");
ansE.value = ansD.value - val3;
}
\t \t </script>
\t </head>
\t <body onload="initialize()">
\t \t <div>
\t \t \t <p>
\t \t \t \t <label for="start">Enter your current clients address:</label>
\t \t \t \t <br>
\t \t \t \t <input type="text" name="start" id="start" />
\t \t \t \t <p>
\t \t \t \t <label for="end">Enter your next clients address: </label>
\t \t \t \t <br>
\t \t \t \t <input type="text" name="end" id="end" />
\t \t \t \t <p>
\t \t \t \t <input type="submit" value="Calculate Route" onclick="calcRoute()" />
\t \t \t \t </p>
\t \t \t \t <label for="odostart">Enter start odometer reading: </label>
\t \t \t \t <br>
<input type="text" name="odostart" id="odostart" onchange="updateDue()">
\t \t \t \t <p>
\t \t \t \t <label for="odoend">Enter end odometer reading: </label>
\t \t \t \t <br>
<input type="text" name="odoend" id="odoend" onchange="updateDue()">
\t \t \t \t <p>
\t \t \t \t <label for="kmused">Total KMs used</label><br>
<input type="text" name="kmused" id="kmused">
\t \t \t \t <p>
\t \t \t \t <label for="kmpriv">Private KMs used</label><br>
<input type="text" name="kmpriv" id="kmpriv">
\t \t \t \t <p>
\t
\t \t \t \t <p>
\t \t \t \t <label for="distance">Distance to next client (km): </label><br>
\t \t \t \t <input type="text" name="distance" id="distance" onchange="updateDue()" />
\t \t \t \t <p>
\t \t \t \t <label for="duration">Duration to next client (min): </label><br>
\t \t \t \t <input type="text" name="duration" id="duration" onchange="updateDue()" />
\t \t \t </p>
\t \t \t
\t \t </div>
\t \t <div id="map_canvas"></div>
\t </body>
</html>
謝謝我在哪裏放置math.round – Hsan
@Hsan您可以調用'Math.round(insert_time_var_here)'並在函數中使用它來代替'insert_time_var_here'。你明白我在說什麼嗎? – StardustGogeta
@Hsan你有工作嗎? – StardustGogeta