1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
initAutocomplete() {
let autocomplete = new google.maps.places.Autocomplete(document.getElementById('addressForth') as HTMLInputElement);
autocomplete.addListener("place_changed", () => {
this.ngZone.run(() => {
//retrouver les lieux
let place: google.maps.places.PlaceResult = autocomplete.getPlace();
// console.log('place is ', place);
// this.form.address1 = place.formatted_address;
this.addressForth = place.formatted_address
//console.log('address 1 ', this.form.address1);
console.log(this.bookingForm);
this.bookingForm.patchValue({
addressForth : this.addressForth,
addressBack: ""
});
//verify result
if (place.geometry === undefined || place.geometry === null) {
return;
}
});
});
let autocomplete1 = new google.maps.places.Autocomplete(document.getElementById('addressBack') as HTMLInputElement);
autocomplete1.addListener("place_changed", () => {
this.ngZone.run(() => {
//retrouver les lieux de l'address 2
let place1: google.maps.places.PlaceResult = autocomplete1.getPlace();
this.addressBack = place1.formatted_address
// console.log('pickup ', this.form.pickupLocation);
console.log(this.bookingForm);
this.bookingForm.patchValue({
addressForth : this.addressForth || "",
addressBack: this.addressBack
});
//verify result
if (place1.geometry === undefined || place1.geometry === null) {
return;
}
});
});
let autocomplete2 = new google.maps.places.Autocomplete(document.getElementById('addressForth1') as HTMLInputElement);
autocomplete2.addListener("place_changed", () => {
this.ngZone.run(() => {
//retrouver les lieux de l'address 2
let place2: google.maps.places.PlaceResult = autocomplete2.getPlace();
this.addressForth = place2.formatted_address
// console.log('pickup ', this.form.pickupLocation);
this.bookingForm.patchValue({
addressForth : this.addressForth || "",
addressBack: this.addressBack
});
//verify result
if (place2.geometry === undefined || place2.geometry === null) {
return;
}
});
});
let autocomplete3 = new google.maps.places.Autocomplete(document.getElementById('addressBack1') as HTMLInputElement);
autocomplete3.addListener("place_changed", () => {
this.ngZone.run(() => {
//retrouver les lieux de l'address 2
let place3: google.maps.places.PlaceResult = autocomplete3.getPlace();
this.addressBack = place3.formatted_address
// console.log('pickup ', this.form.pickupLocation);
this.bookingForm.patchValue({
addressForth : this.addressForth || "",
addressBack: this.addressBack
});
//verify result
if (place3.geometry === undefined || place3.geometry === null) {
return;
}
});
});
}
getDist(): Promise<any>{
if (this.addressForth != undefined && this.addressBack === undefined) {
return this.mapService.calculerDistance(this.addressForth, this.addressPartner)
.then((data) => {
this.distanceForth = data.distance;
this.durationForth = data.distance;
this.formulaBooking = this.bookingForm.value.formulaBooking;
this.tarif = this.mapService.calculTarifTwoAddress(this.distanceForth, this.formulaBooking);
localStorage.setItem('tarif', JSON.stringify(this.tarif));
console.log('tarif',this.tarif);
});
} else if (this.addressForth === undefined && this.addressBack != undefined) {
return this.mapService.calculerDistance(this.addressPartner, this.addressBack)
.then((data) => {
this.distanceBack = data.distance;
this.durationBack = data.duration;
this.formulaBooking = this.bookingForm.value.formulaBooking;
this.tarif = this.mapService.calculTarifTwoAddress(this.distanceBack, this.formulaBooking);
localStorage.setItem('tarif', JSON.stringify(this.tarif));
console.log('tarif',this.tarif);
});
} else if (this.addressForth != undefined && this.addressBack != undefined) {
(
this.mapService.calculerDistance(this.addressForth, this.addressPartner)
.then((data) => {
this.distanceForth = data.distance;
this.durationForth = data.duration;
localStorage.setItem('distanceForth', JSON.stringify(this.distanceForth));
localStorage.setItem('durationForth', JSON.stringify(this.durationForth));
})
);
(
this.mapService.calculerDistance(this.addressPartner, this.addressBack)
.then((data) => {
this.distanceBack = data.distance;
this.durationBack = data.duration;
localStorage.setItem('distanceBack', JSON.stringify(this.distanceBack));
localStorage.setItem('durationBack', JSON.stringify(this.durationBack));
})
)
this.tarif = this.mapService.calculTarifThreeAddress(this.distanceForth, this.distanceBack, this.formulaBooking);
console.log('tarif condition 3', this.tarif);
}} |