Ordering with directionsService - google maps

0

I have a problem with the ordering of local google maps. I have an array of latitude objects to be sent:

waypoints = [
 location:{
 lat: -8.116597,
 lng: -79.0347417
},
location:{
 lat: -8.120997,
 lng: -79.038355
},
location:{
 lat: -8.120151,
 lng: -79.037014
},
location:{
 lat: -8.119195,
 lng: -79.036657
},
]

and in this way I send to google maps

this.$refs.mapa.$mapCreated.then(() => {
          this.directionsService = new google.maps.DirectionsService();
          this.directionsDisplay.setMap(this.$refs.mapa.$mapObject);
          this.directionsService.route({
            origin: { lat: -8.0828174, lng: -79.0953881 },
            destination: this.waypoints[this.waypoints.length - 1].location,
            waypoints: this.waypoints,
            travelMode: 'DRIVING',
            optimizeWaypoints: true,
          }, (r, status) => {
              if (status === 'OK') {
                this.directionsDisplay.setDirections(r);
                console.log(r.routes[0].waypoint_order);
                }
            });
        });

In which should bring me the closest points of the origin and if it does. The problem occurs when I make changes in order to send the array of objects. for example if I order to order print the following order:

[0, 1, 2, 4, 3, 5]

but if I change the order of the array and then send it to order it prints another order:

[1, 2, 3, 4, 0, 5]

I do not know why this happens if I'm sending the same positions to the finals. Is there something I'm missing?

    
asked by Piero Pajares 18.04.2018 в 19:04
source

0 answers