NG-图显示两个点(航点)之间的最佳方式 [英] ng-map show the best way between two points (waypoints)

查看:184
本文介绍了NG-图显示两个点(航点)之间的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有IonicFramework和NG-MAP Angularjs。我在这里阅读所有的文档(链接),但我不觉得我该怎么让用户最好的方式(或以简单的方式),以去用户的当前位置到另一个

I am using Angularjs with IonicFramework and ng-map. I have read all the documentation here (link), but I don't find how can I show to the user the best way (or a simple way) to go to the user current position to another.

我读<一个href=\"https://developers.google.com/maps/documentation/javascript/examples/directions-waypoints?hl=es\"相对=nofollow>这也和这个,但我想用棱角分明。

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

推荐答案

这是我做的和工作;)

$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();


    });

这篇关于NG-图显示两个点(航点)之间的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆