3
<!DOCTYPE html>
 <html>
<head>
<title>Travel modes in directions</title>
 <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
 <script src="http://maps.google.com/maps/api/js?libraries=placeses,visualization,drawing,geometry,places"></script>
     <script src="http://code.angularjs.org/1.3.15/angular.js">   </script>
  <script src="http://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<style>
  html, body {width:100%; height: 100%; padding:0; margin: 0}
  body {padding: 5px}
  * { box-sizing: border-box; }
</style>
    </head>
  <body ng-app="ngMap">
       <div style="width: 68%; float:left; height: 100%">
   <div ng-app="" ng-init="loc='current-location'">

   Destination: <input type="text"  ng-model="loc">


   </div>
  <ng-map zoom="14" center="current-location" style="height:90%" >
    <directions
      draggable="true"
      panel="directions-panel"
      travel-mode="DRIVING"
      origin="current-location"
      destination="{{loc}}">
    </directions>
  </ng-map>


  Directions path length:{{map.directionsRenderers[0].directions.routes[0].overview_path.length}}
</div>


<div id="directions-panel" style="width: 28%; float:left; height: 100%; overflow: auto; padding: 0px 5px">
</div>

this is my code to get the driving directions between two points. The directions to path length used to calculate the distance is not similar to the actual distance between the points.. is there a way i can find the actual distance between the points?? Plz help

sachin hunur
  • 281
  • 2
  • 6
  • 17

1 Answers1

0

If you are looking for the geodesic distance between two points other than the distance along streets between origin and destination, you should use google.maps.geometry.spherical namespace. in angular, use google.maps.geometry.spherical.computeDistanceBetween(from:LatLng, to:LatLng, radius?:number) to get the distance or google.maps.geometry.spherical.computeLength(path:Array<LatLng>|MVCArray<LatLng>, radius?:number) to get the geodesic length between two points.

The $scope.map is just the scope object you set up, the actual name depends on how your setup is.

Good Luck!

Here is the resource.

Downhillski
  • 2,555
  • 2
  • 27
  • 39