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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 DosasCommented:
function taxi(distance,cost){
  return distance*cost;

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

Open in new window

Scott Fell, EE MVEDeveloper & 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

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).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.