I'm trying to create a codepen which calculates the distance from point A to point B and C. Also let's say for argument's sake that fuel/gas costs £1 per mile. I'm trying to add up the total distance between all the points (based on user input) and then multiply it by the fuel price and display it to the user.
I'm trying to use the Google Distance Matrix API to achieve this.
I have obviously taken out my API key since you need to pay for it but it works.
The documentation is great but it the locations are hard coded and i'm not sure how to right the code so it takes the result and multiplies it by the fuel price.
I'm trying to make it something like this:
const locationA = document.getElementById = "locationA".value;
const locationB = document.getElementById = "locationB".value;
const locationC = document.getElementById = "locationC".value;
let totalDistance = locationA + locationB + locationC
let fuel price = 1
let totalPrice = fuelPrice * totalDistance
document.write(totalPrice)
body{
text-align: center;
}
p {
color: #969696;
font-style: italic;
margin: 20px 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<h3>Fuel Price Est.</h3>
<label>Location A</label>
<br>
<input type="text" placeholder="Street address, P.O. Box, Company Name..." id="locationA">
<br>
<label>Location B</label>
<br>
<input type="text" placeholder="Street address, P.O. Box, Company Name..." id="locationB">
<br>
<label>Location C</label>
<br>
<input type="text" placeholder="Street address, P.O. Box, Company Name..." id="locationC">
<p>(Est based on £1 per mile basis)</p>
<div id="result">
</div>
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
</body>
</html>