html code or algorithm


i need taxi fare calculator algorithm as distance km based between two points in same city  for web site
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.

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).
Leonidas DosasCommented:
Could you be more specific? Give us an example.
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
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

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,output
<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src=""></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

<input id="distance" value="30">
<input id="rate" value="5">
  <button id="calculate">Calculate</button>  
  <div id="fare"></div>  

Open in new window

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.