Calculate the distance between 2 locations and calculate a price
<p>So basically I have this script (credits to 1stwebdesigner.com and geocodezip) which calculates the distance between 4 locations.
Location 1, location 2, location 3, location 4.
I now need to calculate the distance between location2 and location 3.
and also get that distance and display it and display a price according to this formula</p>

<ol>
<li>0-10kms = $99,</li>
<li>11-20kms plus $5 per each additional km,</li>
<li>21 - 35kms plus $3.75 per each additional km,</li>
<li>36kms+ plus $3.50 per each additional km,</li>
</ol>

<p>How do I go about this?</p>

<p>So far I have this (Credits to Rajaprabhu)
(<a href="https://stackoverflow.com/questions/24179939/price-calculation-based-on-the-distance-covered">Price Calculation based on the distance covered</a>)
, problem 1 is, the formula is wrong for my situation and problem 2 is the formula isn't getting the distance from the previous calculation.</p>

<pre><code>var request = {
    origin:location2, 
    destination:location3,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) 
{
    if (status == google.maps.DirectionsStatus.OK) 
    {
        var distance = response.routes[0].legs[0].distance.text;
        var duration = response.routes[0].legs[0].duration.text;
        var dvDistance = document.getElementById("dvDistance");
        dvDistance.innerHTML = "";
        dvDistance.innerHTML += "The one way Distance is: " + distance + "&lt;br /&gt;";
        dvDistance.innerHTML += "The one way Duration is: " + duration;

        //calculate the one way price using the klms
        var kms = distance;
        var price_1 = (kms &gt; 0) ? 3 : 0; kms =  (kms &gt; 0)? kms - 1 :  0;
        var price_2 = (kms - 14) &gt; 0 ? (14 * 1.60) : (kms * 1.60); kms = (kms-14)&gt;0 ? kms - 14 : 0;
        var price_3 = (kms - 15) &gt; 0 ? (15 * 1.40) : (kms * 1.40); kms = (kms-15)&gt;0 ? kms - 15 : 0;
        var price_4 = (kms &gt; 0) ? (kms * 1.20) : 0;

        document.getElementById("displayprice").innerHTML = "the one way price is: " + (price_1 + price_2 + price_3 + price_4);


    }
});
</code></pre>

<p>Stuck on the formula now. 
1. anything over 35km gives a incorrect result.
2. 10km and under should really default to $99.</p>

<pre><code>//calculate the one way price using the klms
                var kms = distance;
                console.log(kms);
                var price_1 = (kms &gt; 0) ? 99 : 0; kms =  (kms &gt; 0)? kms - 10 :  0;
                var price_2 = (kms - 10) &gt; 0 ? (10 * 5.00) : (kms * 5.00); kms = (kms-10)&gt;0 ? kms - 10 : 0;
                var price_3 = (kms - 20) &gt; 0 ? (15 * 3.75) : (kms * 3.75); kms = (kms-20)&gt;0 ? kms - 20 : 0;
                var price_4 = (kms &gt; 0) ? (kms * 3.50) : 0;
</code></pre>