title: Get shortest distance between two points
body: <p>I need to calculate <strong>shortest</strong> distance between two points. I am using below function to achieve that.</p>
  
  <pre><code>var p1 = new google.maps.LatLng(6.71532762,80.06215197);
  var p2 = new google.maps.LatLng(6.93234287,79.84870747);
  
  var distance = document.getElementById('distance');
  distance.innerHTML = distance.innerHTML+calcDistance(p1, p2);
  
  //calculates distance between two points in km's
  function calcDistance(p1, p2) {
    return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(2);  
  } 
  </code></pre>
  
  <p>This gives <strong>33.77 km</strong> as distance. But according to <a href="https://www.google.com/maps/dir/6.71532762,80.06215197/6.93234287,79.84870747" rel="nofollow noreferrer">google maps</a>, <strong>shortest</strong> distance between above points should be <strong>45.0 km</strong>.</p>
  
  <p>How could I get that value? (<strong>45.0 km</strong>)</p>
  
  <p>Here is the <a href="https://jsfiddle.net/uc6t7br5/" rel="nofollow noreferrer">jsfiddle link</a>.</p>