Bonjour,

Je me sers de google map pour mon projet pour l'autocomplete des adresses et pour le calcul des trajets. Cela fonctionnait parfaitement jusqu'à ce matin.

Lorsque je rentre une adresse il me sort l'erreur suivante :

InvalidValueError: in property destinations: at index 0: not a string; and not a LatLng or LatLngLiteral: not an Object; and not an Object
Je n'ai rien changé dans mon code du coup je ne comprends pas trop cette erreur.

voici le code de mon service

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
  public calculerDistance(origin: string, dest: string): Promise<any> {
    let promise = new Promise((resolve, reject) => {
      return new google.maps.DistanceMatrixService()
      .getDistanceMatrix({'origins': [origin], 'destinations': [dest], travelMode: google.maps.TravelMode.DRIVING},
        (results: any) => {
          // console.log('distance entre les -- ', results.rows[0].elements[0].distance.value/1000);
          this.distance = results.rows[0].elements[0].distance.value/1000;
          this.duration = results.rows[0].elements[0].duration.value/60;
          // console.log('disatnce',this.distance);
          // console.log('duration', this.duration);
          // enregistrer le result sur le storage local de votre navigateur
          localStorage.setItem('distance', JSON.stringify(this.distance));
          localStorage.setItem('duration', JSON.stringify(this.duration));
          resolve({ distance: this.distance, duration: this.duration});
        }
      );
    });
    return promise;
  }
 
  public calculTarifTwoAddress (distanceForth, formulaBooking) {
    if (distanceForth <= 5 && formulaBooking === 'forth') {
       return '29,90€';
     }
     else if ((distanceForth > 5 && distanceForth <= 10) && formulaBooking === 'forth') {
       return '39,90€';
     }
     else if ((distanceForth > 10 && distanceForth <= 15) && formulaBooking === 'forth') {
       return '49,90€';
     }
     else if (distanceForth <= 5 && formulaBooking === 'back') {
       return '29,90€';
     }
     else if ((distanceForth > 5 && distanceForth <= 10) && formulaBooking === 'back') {
       return '39,90€';
     }
     else if ((distanceForth > 10 && distanceForth <= 15) && formulaBooking === 'back') {
       return '49,90€';
     }
     else {
       return 'nous contacter';
     }
 
 }
 
 public calculTarifThreeAddress (distanceForth, distanceBack, formulaBooking) {
   if (distanceForth <= 5 && distanceBack <= 5 && formulaBooking === 'round') {
     return this.tarif = '49,90€';
   }
   else if (distanceForth <= 5 && (distanceBack > 5 && distanceBack <=10) && formulaBooking === 'round') {
     return this.tarif = '69,90€';
   }
   else if ((distanceForth <= 5 ) && (distanceBack > 10 && distanceBack <= 15) && formulaBooking === 'round') {
     return this.tarif = '79,90€';
   }
   else if ((distanceBack <= 5 ) && (distanceForth > 5 && distanceForth <= 10) && formulaBooking === 'round') {
     return this.tarif = '69,90€';
   }
   else if ((distanceForth > 5 && distanceForth <= 10) && (distanceBack > 5 && distanceBack <= 10) && formulaBooking === 'round') {
     return this.tarif = '69,90€';
   }
   else if ((distanceForth > 5 && distanceForth <= 10) && (distanceBack > 10 && distanceBack <= 15) && formulaBooking === 'round') {
     return this.tarif = '89,90€';
   }
   else if ((distanceForth > 10 && distanceForth <= 15) && distanceBack <= 5 && formulaBooking === 'round') {
     return this.tarif = '79,90€';
   }
   else if ((distanceForth > 10 && distanceForth <= 15) && (distanceBack > 5 && distanceBack <= 10) && formulaBooking === 'round') {
     return this.tarif = '89,90€';
   }
   else if ((distanceForth > 10 && distanceForth <= 15) && (distanceBack > 10 && distanceBack <= 15) && formulaBooking === 'round') {
     return this.tarif = '89,90€';
   }
   else {
     return this.tarif = 'nous contacter';
   }
 }
et le code de mon component

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  initAutocomplete() {
    let autocomplete = new google.maps.places.Autocomplete(document.getElementById('address') 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.address = place.formatted_address
        //console.log('address 1 ', this.form.address1);
        this.bookingForm.patchValue({
          address : this.address
        });
        //verify result
        if (place.geometry === undefined || place.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>{
    this.formulaBooking = this.bookingForm.value.formulaBooking;
    if (this.bookingForm.value.address !== '') {
      return this.mapService.calculerDistance(this.address, this.addressPartner)
      .then((data) => {
        if (this.formulaBooking === 'forth') {
          this.distanceForth = data.distance;
          this.durationForth = data.duration;
          this.tarif = this.mapService.calculTarifTwoAddress(this.distanceForth, this.formulaBooking);
          localStorage.setItem('tarif', JSON.stringify(this.tarif));
          // console.log('compenent condition 1 service distance', JSON.parse(localStorage.getItem('distance')));
          // console.log('compenent condition 1 service duration', JSON.parse(localStorage.getItem('duration')));
          this.addressForth = this.bookingForm.value.address;
          localStorage.setItem('address', JSON.stringify(this.addressForth));
          // localStorage.setItem('addressBack', JSON.stringify(this.addressBack));
          // console.log('compenent condition 1 local addressForth', JSON.parse(localStorage.getItem('addressForth')));
          // console.log('compenent condition 1 local addressBack', JSON.parse(localStorage.getItem('addressBack')));
          this.addressForth = JSON.parse(localStorage.getItem('address'));
          // console.log('compenent condition 1 addressForth',this.addressForth);
          // console.log('compenent condition 1 addressBack',this.addressBack);
          // console.log('compenent condition 1 component distanceForth', this.distanceForth);
          // console.log('compenent condition 1 component  durationForth', this.durationForth);
          // console.log('compenent condition 1 component distanceBack', this.distanceBack);
          // console.log('compenent condition 1 component  durationBack', this.durationBack);
          // console.log('component constion 1 formula', this.formulaBooking);
          // console.log('component constion 1 tarif',this.tarif);
          // console.log('compenent condition 1 local distance', localStorage.removeItem('distance'));
          // console.log('compenent condition 1 local duration', localStorage.removeItem('duration'));
          // console.log('compenent condition 1 local address', localStorage.removeItem('address'));
          // this.addressForth = "";
          // this.distanceForth = 0;
          // this.durationForth = 0;
          this.rebuilderForm();
        }
        else if (this.formulaBooking === 'back') {
          this.distanceBack = data.distance;
          this.durationBack = data.duration;
          this.tarif = this.mapService.calculTarifTwoAddress(this.distanceBack, this.formulaBooking);
          localStorage.setItem('tarif', JSON.stringify(this.tarif));
          // console.log('compenent condition 2 service distance', JSON.parse(localStorage.getItem('distance')));
          // console.log('compenent condition 2 service duration', JSON.parse(localStorage.getItem('duration')));
          this.addressBack = this.bookingForm.value.address;
          localStorage.setItem('address', JSON.stringify(this.addressBack));
          // console.log('compenent condition 2 local addressForth', JSON.parse(localStorage.getItem('addressForth')));
          // console.log('compenent condition 2 local addressBack', JSON.parse(localStorage.getItem('addressBack')));
          // console.log('compenent condition 2 addressForth',this.addressForth);
          // console.log('compenent condition 2 addressBack',this.addressBack);
          // console.log('compenent condition 2 component distanceForth', this.distanceForth);
          // console.log('compenent condition 2 component  durationForth', this.durationForth);
          // console.log('compenent condition 2 component distanceBack', this.distanceBack);
          // console.log('compenent condition 2 component  durationBack', this.durationBack);
          // console.log('component constion 2 formula', this.formulaBooking);
          // console.log('component constion 2 tarif',this.tarif);
          // console.log('compenent condition 2 local distance', localStorage.removeItem('distance'));
          // console.log('compenent condition 2 local duration', localStorage.removeItem('duration'));
          // console.log('compenent condition 2 local address', localStorage.removeItem('address'));
          // this.addressBack = "";
          // this.distanceBack = 0;
          // this.durationBack = 0;
          this.rebuilderForm();
        }
      });
    }
    else if (this.bookingForm.value.addressForth !== '' && this.bookingForm.value.addressBack !== '') {
      this.mapService.calculerDistance(this.addressForth, this.addressPartner)
      .then((data) => {
        if (this.formulaBooking === 'round') {
          this.distanceForth = data.distance;
          this.durationForth = data.duration;
          localStorage.setItem('tarif', JSON.stringify(this.tarif));
          // console.log('compenent condition 1 service distance', JSON.parse(localStorage.getItem('distance')));
          // console.log('compenent condition 1 service duration', JSON.parse(localStorage.getItem('duration')));
          this.addressForth = this.bookingForm.value.addressForth;
          localStorage.setItem('address', JSON.stringify(this.addressForth));
          // localStorage.setItem('addressBack', JSON.stringify(this.addressBack));
          // console.log('compenent condition 1 local addressForth', JSON.parse(localStorage.getItem('addressForth')));
          // console.log('compenent condition 1 local addressBack', JSON.parse(localStorage.getItem('addressBack')));
          this.addressForth = JSON.parse(localStorage.getItem('address'));
          // console.log('compenent condition 1 addressForth',this.addressForth);
          // console.log('compenent condition 1 addressBack',this.addressBack);
          // console.log('compenent condition 1 component distanceForth', this.distanceForth);
          // console.log('compenent condition 1 component  durationForth', this.durationForth);
          // console.log('compenent condition 1 component distanceBack', this.distanceBack);
          // console.log('compenent condition 1 component  durationBack', this.durationBack);
          // console.log('component constion 1 formula', this.formulaBooking);
          // console.log('component constion 1 tarif',this.tarif);
          // console.log('compenent condition 1 local distance', localStorage.removeItem('distance'));
          // console.log('compenent condition 1 local duration', localStorage.removeItem('duration'));
          // console.log('compenent condition 1 local address', localStorage.removeItem('address'));
        }
        else if (this.formulaBooking === 'technicalControl') {
          this.distanceForth = data.distance;
          this.durationForth = data.duration;
          this.tarif = this.mapService.calculTarifTwoAddress(this.distanceForth, this.formulaBooking);
          localStorage.setItem('tarif', JSON.stringify(this.tarif));
          // console.log('compenent condition 2 service distance', JSON.parse(localStorage.getItem('distance')));
          // console.log('compenent condition 2 service duration', JSON.parse(localStorage.getItem('duration')));
          this.addressBack = this.bookingForm.value.addressForth;
          localStorage.setItem('address', JSON.stringify(this.addressForth));
          // console.log('compenent condition 2 local addressForth', JSON.parse(localStorage.getItem('addressForth')));
          // console.log('compenent condition 2 local addressBack', JSON.parse(localStorage.getItem('addressForth')));
          // console.log('compenent condition 2 addressForth',this.addressForth);
          // console.log('compenent condition 2 addressBack',this.addressBack);
          // console.log('compenent condition 2 component distanceForth', this.distanceForth);
          // console.log('compenent condition 2 component  durationForth', this.durationForth);
          // console.log('compenent condition 2 component distanceBack', this.distanceForth);
          // console.log('compenent condition 2 component  durationBack', this.durationForth);
          // console.log('component constion 2 formula', this.formulaBooking);
          // console.log('component constion 2 tarif',this.tarif);
          // console.log('compenent condition 2 local distance', localStorage.removeItem('distance'));
          // console.log('compenent condition 2 local duration', localStorage.removeItem('duration'));
          // console.log('compenent condition 2 local address', localStorage.removeItem('address'));
        }
      });
      this.mapService.calculerDistance(this.addressBack, this.addressPartner)
      .then((data) => {
        if (this.formulaBooking === 'round') {
          this.distanceBack = data.distance;
          this.durationBack = data.duration;
          localStorage.setItem('tarif', JSON.stringify(this.tarif));
          // console.log('compenent condition 2 service distance', JSON.parse(localStorage.getItem('distance')));
          // console.log('compenent condition 2 service duration', JSON.parse(localStorage.getItem('duration')));
          this.addressBack = this.bookingForm.value.addressBack;
          this.tarif = this.mapService.calculTarifThreeAddress(this.distanceForth, this.distanceBack, this.formulaBooking);
          localStorage.setItem('address', JSON.stringify(this.addressBack));
          // localStorage.setItem('addressBack', JSON.stringify(this.addressBack));
          // console.log('compenent condition 2 local addressForth', JSON.parse(localStorage.getItem('addressForth')));
          // console.log('compenent condition 1 local addressBack', JSON.parse(localStorage.getItem('addressBack')));
          this.addressBack = JSON.parse(localStorage.getItem('address'));
          // console.log('compenent condition 2 addressForth',this.addressForth);
          // console.log('compenent condition 2 addressBack',this.addressBack);
          // console.log('compenent condition 2 component distanceForth', this.distanceForth);
          // console.log('compenent condition 2 component  durationForth', this.durationForth);
          // console.log('compenent condition 2 component distanceBack', this.distanceBack);
          // console.log('compenent condition 2 component  durationBack', this.durationBack);
          // console.log('component constion 2 formula', this.formulaBooking);
          // console.log('component constion 2 tarif',this.tarif);
          // console.log('compenent condition 2 local distance', localStorage.removeItem('distance'));
          // console.log('compenent condition 2 local duration', localStorage.removeItem('duration'));
          console.log('compenent condition 2 local address', localStorage.removeItem('address'));
          // this.addressForth = '';
          // this.addressBack = '';
          // this.distanceForth = 0;
          // this.durationForth = 0;
          // this.distanceBack = 0;
          // this.durationBack = 0;
          this.rebuilderForm();
        }
        else if (this.formulaBooking === 'technicalControl') {
          this.distanceBack = data.distance;
          this.durationBack = data.duration;
          this.tarif = this.mapService.calculTarifTwoAddress(this.distanceBack, this.formulaBooking);
          localStorage.setItem('tarif', JSON.stringify(this.tarif));
          // console.log('compenent condition 2 service distance', JSON.parse(localStorage.getItem('distance')));
          // console.log('compenent condition 2 service duration', JSON.parse(localStorage.getItem('duration')));
          this.addressBack = this.bookingForm.value.addressBack;
          localStorage.setItem('address', JSON.stringify(this.addressBack));
          // console.log('compenent condition 2 local addressForth', JSON.parse(localStorage.getItem('addressForth')));
          // console.log('compenent condition 2 local addressBack', JSON.parse(localStorage.getItem('addressBack')));
          // console.log('compenent condition 2 addressForth',this.addressForth);
          // console.log('compenent condition 2 addressBack',this.addressBack);
          // console.log('compenent condition 2 component distanceForth', this.distanceForth);
          // console.log('compenent condition 2 component  durationForth', this.durationForth);
          // console.log('compenent condition 2 component distanceBack', this.distanceBack);
          // console.log('compenent condition 2 component  durationBack', this.durationBack);
          // console.log('component constion 2 formula', this.formulaBooking);
          // console.log('component constion 2 tarif',this.tarif);
          // console.log('compenent condition 2 local distance', localStorage.removeItem('distance'));
          // console.log('compenent condition 2 local duration', localStorage.removeItem('duration'));
          // console.log('compenent condition 2 local address', localStorage.removeItem('address'));
        }
      });
 
    }
  }