Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   getDurations() {
  2.     this.geolocation.getCurrentPosition().then((position) => {
  3.       this.start.latitude = position.coords.latitude;
  4.       this.start.longitude = position.coords.longitude;
  5.       let uber_link = "https://api.uber.com/v1.2/estimates/price?start_latitude=" + this.start.latitude + "&start_longitude=" + this.start.longitude + "&end_latitude=" + this.stop.latitude + "&end_longitude=" + this.stop.longitude;
  6.       let maps_link = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + this.start.latitude + "," + this.start.longitude + "&destinations=" + this.stop.latitude + "," + this.stop.longitude + "&mode=walking&language=fr-FR&key=AIzaSyBscbZVSgZLlBOioFlcaYdXDZQ9tUNXfX4";
  7.       let maps_link_car = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + this.start.latitude + "," + this.start.longitude + "&destinations=" + this.stop.latitude + "," + this.stop.longitude + "&language=fr-FR&key=AIzaSyBscbZVSgZLlBOioFlcaYdXDZQ9tUNXfX4";
  8.       let headers = new Headers();
  9.       headers.append("Authorization", "Token UbD_Cz-HqZirZHA1_Ys-hDj5ojeZttX3YkY-BDH_");
  10.       headers.append("Accept-Language", "fr_FR");
  11.       this.http.get(uber_link, { headers: headers })
  12.         .map(response => response.json())
  13.         .subscribe(data => {
  14.           this.uber_duration = data.prices[0].duration / 60 + "";
  15.           this.uber_price = data.prices[0].estimate;
  16.           var price = this.uber_price.slice(4, 7);
  17.           var start_price = this.uber_price.slice(0, 2);
  18.           this.uber_price = start_price + price + " €";
  19.         })
  20.       this.http.get(maps_link)
  21.         .map(response => response.json())
  22.         .subscribe(data => {
  23.           if (data.rows[0].elements[0].duration)
  24.             this.maps_duration_walk = data.rows[0].elements[0].duration.text
  25.         })
  26.       this.http.get(maps_link_car)
  27.         .map(response => response.json())
  28.         .subscribe(data => {
  29.           if (data.rows[0].elements[0].duration)
  30.             this.maps_duration_car = data.rows[0].elements[0].duration.text
  31.         })
  32.     });
  33.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement