Как назначить идентификатор с помощью Google Maps Route API - PullRequest
0 голосов
/ 17 сентября 2018

Я занимаюсь разработкой приложения со службой направления маршрутов карт Google, как эта функция ( directionsService.route ) выполняется асинхронно, как можно присвоить идентификатор ( var id = this.rutas[i] .id ) к каждому прорисованному маршруту.Это мой код:

directionsService = new google.maps.DirectionsService();
    this.rutaService.obtenerRutas().then(response => {
      this.rutas = response;
      for(var i=0;i<this.rutas.length;i++){
          var routeData= this.rutas[i].routeData;
          var str = routeData;
          var obj=JSON.parse(str);
          originLng = obj.origin.originLng;
          originLat = obj.origin.originLat;
          destinationLat = obj.destination.destinationLat;
          destinationLng = obj.destination.destinationLng;

          var id= this.rutas[i].id;//Route ID

          if(obj.waypoints.length>0){

             for(var j=0;j<obj.waypoints.length;j++){

               waypts.push({
                   location: new google.maps.LatLng(obj.waypoints[j][0], obj.waypoints[j][1]),
                   stopover: true
               });
             }
             req = {
                 origin:new google.maps.LatLng(originLat, originLng),
                 destination: new google.maps.LatLng(destinationLat, destinationLng),
                 waypoints: waypts,
                 travelMode: google.maps.DirectionsTravelMode.DRIVING
              };

              waypts = [];
          }else{
             req = {
                 origin:new google.maps.LatLng(originLat, originLng),
                 destination: new google.maps.LatLng(destinationLat, destinationLng),
                 travelMode: google.maps.DirectionsTravelMode.DRIVING
              };
           }
          directionsService.route(req, function(result, status) {
                console.log(status);
                if (status === google.maps.DirectionsStatus.OK) {
                    var col = '#' + (( 1 << 24) * Math.random() | 0).toString(16);
                    var pinImage = new google.maps.MarkerImage('http://www.googlemapsmarkers.com/v1/27893e/');
                    originMarker = new google.maps.Marker({
                      position: req.origin,
                      icon: pinImage
                    });
                    originMarkers[cur] = originMarker;
                    originMarkers[cur].setMap(map);
                    pinImage = new google.maps.MarkerImage('http://www.googlemapsmarkers.com/v1/7d2181/');
                    destinationMarker = new google.maps.Marker({
                      position: req.destination,
                      icon: pinImage
                    });
                    destinationMarkers[cur] = destinationMarker;
                    destinationMarkers[cur].setMap(map);
                    var color = col;
                    directionsDisplay = new google.maps.DirectionsRenderer({
                      polylineOptions: {
                        strokeColor: color
                      }
                    });
                    renderArray[cur] = directionsDisplay;
                    renderArray[cur].setOptions({suppressMarkers: true});
                    renderArray[cur].setMap(map);
                    renderArray[cur].setDirections(result);
                    cur++;

                }
            });
            map.setZoom(10);
            map.setCenter(new google.maps.LatLng(originLat, originLng));
       }
    });

Почему я получаю 'OVER_QUERY_LIMIT' в статусе с некоторыми маршрутами, которые я пытаюсь нарисовать ?.Любая помощь приветствуется.

...