# 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
###### Who is Participating?

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

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

Commented:
Could you be more specific? Give us an example.
0
Elec.&Elctro.Engr.Author Commented:
airtport in A Point distance from it 30 km far away from airport fare within constant cost per km
0
Commented:
``````function taxi(distance,cost){
return distance*cost;
}

console.log(taxi(30, 30));
``````
0
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>
<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>
<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>
``````
0
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).
0

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.

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