Ng-map shows the best path between two points (waypoints)

I am using Angularjs with IonicFramework and ng-map. I've read all the documentation here ( link ), but I can't find how I can show the user a better way (or just a path) to navigate to the user's current position to another.

I have read this and this too , but I would like to use angular.

+3


source to share


2 answers


This is what I do and work;)



$scope.centerOnMe= function(){
    $scope.positions = [];


    $ionicLoading.show({
      template: 'Obteniendo localizaciΓ³n...'
    });



    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      $scope.positions.push({lat: pos.k,lng: pos.B});
      console.log(pos);
      $scope.map.setCenter(pos);
      $ionicLoading.hide();




      var directionsDisplay = new google.maps.DirectionsRenderer();;
      var directionsService = new google.maps.DirectionsService();


      console.log($scope.map);
      directionsDisplay.setMap($scope.map);

      function calcRoute() {
        var start = "37.891586,-4.7844853";
        var end = pos.k + "," + pos.B;



        var request = {
          origin: start,
          destination: end,
          optimizeWaypoints: true,
          travelMode: google.maps.TravelMode.DRIVING
        };

        directionsService.route(request, function(response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);            
            console.log('enter!');  
          }
        });


      }

      calcRoute();


    });

      

+3


source


I would try angular-ui-maps https://angular-ui.github.io/angular-google-maps/#!/api

and google pointers: https://developers.google.com/maps/documentation/directions/



With the google api you can get the waypoints for your trip and then draw it on the map canvas using the polylines directive.

+2


source







All Articles