Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70429

Função assincrona

$
0
0

@greisson wrote:

Prezados, como faço para pegar os steps da função service.routes do geolocation e passar para outra função? Ela é assincrona e não estou conseguindo passar essas informações para outra função.

traceRoute(service: any, display: any, request: any){

  service.route(request, function (result, status) {
    if (status == 'OK') {
      let latTraceRoute;
      let lngTraceRoute;
      let latlngTraceRoute;
      var arrayLatLng = [];
      //alert(JSON.stringify(result.routes[0].legs[0].steps.length));
      for (let index = 0; index < result.routes[0].legs[0].steps.length; index++) {
        //console.log(result.routes[0].legs[0].steps[index].start_location);  
        //alert(result.routes[0].legs[0].steps[index].start_location);
        latlngTraceRoute = JSON.stringify(result.routes[0].legs[0].steps[index].start_location).split(',',2);
        
        latTraceRoute = latlngTraceRoute[0].split(':',2);
        lngTraceRoute = latlngTraceRoute[1].split(':',2);

        latTraceRoute = latTraceRoute[1];
        lngTraceRoute = lngTraceRoute[1].replace('}','');
        
        arrayLatLng[index] = [latTraceRoute,lngTraceRoute];
        
        if (index == result.routes[0].legs[0].steps.length-1) {
          **this.steps =  arrayLatLng;**
        }
        

      }
      display.setDirections(result);
     
    }
  });

A variavel this.steps que quero passar para outra função. Alguém poderia dar uma força?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>