html code or algorithm

hye,

i need taxi fare calculator algorithm as distance km based between two points in same city  for web site
thnx,
LVL 5
Nadir ALTINBASElec.&Elctro.Engr.Asked:
Who is Participating?
 
gr8gonzoConnect With a Mentor ConsultantCommented:
First, you likely need to use something like the driving distance matrix API to determine true driving distance and best route and account for traffic conditions.

https://developers.google.com/maps/documentation/distance-matrix/intro

You can't just calculate direct distance between two points. There are usually multiple routes between two points. Usually taxis charge for both time and distance because if they need to be paid for opportunity and for fuel, which are not dependent on distance.

Once you have the distance, then you just multiple the distance times the per km cost and factor in any other costs (e.g. time, toll road fees, etc).
0
 
Leonidas DosasCommented:
Could you be more specific? Give us an example.
0
 
Nadir ALTINBASElec.&Elctro.Engr.Author Commented:
airtport in A Point distance from it 30 km far away from airport fare within constant cost per km
0
 
Leonidas DosasConnect With a Mentor Commented:
function taxi(distance,cost){
  return distance*cost;
}

console.log(taxi(30, 30));
alert(taxi(30, 30));

Open in new window

0
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
You will need to use a scripting language like javascript or serverside language like php or .net or java.  In js/jquery
http://jsbin.com/bomuhutili/edit?html,output
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://code.jquery.com/jquery-git.js"></script>
<script>
  $(function(){ //START WHEN PAGE IS LOADED
  
  $('button#calculate').on('click',function(){ // LISTEN FOR THE BUTTON CLICK
    
    var distance = $('input#distance').val(); // VARIABLE FOR TOTAL DISTANCE
    var rate = $('input#rate').val(); // VARIABLE FOR TEH RATE  PER MILE
    
    var fare = distance * rate; // CALCULTE FARE DISTANCE * RATE
    
    $('#fare').html('Your fare is $'+fare); //PLACE FARE INSIDE THE DIV WITH ID fare
  });
});

  </script>
</head>
<body>
 Distance<br>
<input id="distance" value="30">
  <br>
 Rate<br>  
<input id="rate" value="5">
  <br>
  <button id="calculate">Calculate</button>  
  <div id="fare"></div>  
</body>
</html>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.