Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getDurations() {
- this.geolocation.getCurrentPosition().then((position) => {
- this.start.latitude = position.coords.latitude;
- this.start.longitude = position.coords.longitude;
- 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;
- 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";
- 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";
- let headers = new Headers();
- headers.append("Authorization", "Token UbD_Cz-HqZirZHA1_Ys-hDj5ojeZttX3YkY-BDH_");
- headers.append("Accept-Language", "fr_FR");
- this.http.get(uber_link, { headers: headers })
- .map(response => response.json())
- .subscribe(data => {
- this.uber_duration = data.prices[0].duration / 60 + "";
- this.uber_price = data.prices[0].estimate;
- var price = this.uber_price.slice(4, 7);
- var start_price = this.uber_price.slice(0, 2);
- this.uber_price = start_price + price + " €";
- })
- this.http.get(maps_link)
- .map(response => response.json())
- .subscribe(data => {
- if (data.rows[0].elements[0].duration)
- this.maps_duration_walk = data.rows[0].elements[0].duration.text
- })
- this.http.get(maps_link_car)
- .map(response => response.json())
- .subscribe(data => {
- if (data.rows[0].elements[0].duration)
- this.maps_duration_car = data.rows[0].elements[0].duration.text
- })
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement