Update
Regarding the import LatLngBounds = google.maps.LatLngBounds; , then I found that I called custructor ( new LatLngBounds() ) before initializing the Maps api. In fact, I am using @agm/core; . And the constructor should be called after load() as shown below
ngOnInit() { this.mapsAPILoader.load().then(() => { this.page$.subscribe(page => { if (page && page.content) { this.latLngBounds = new google.maps.LatLngBounds(); page.content.forEach(w => this.latLngBounds.extend(new google.maps.LatLng(lat, lng))); } }); } ); }
and I added the following import to my typings.d.ts
import {} from '@types/googlemaps';
Original answer
I solved my problem with the following configuration:
1- package.json
"dependencies": { ... "googlemaps": "^1.12.0", ... }
2- tsconfig.json
"types": [ ... "googlemaps" ]
3- And add google api script to my index.html
<head> ... </head> <body> <app-root>Loading...</app-root> <script src="https://maps.googleapis.com/maps/api/js?key=KEY&libraries=places&language=fr" async defer></script> </body> </html>
4- In components use it as below
declare var google: any; @Component({ ... }) export class SearchComponent implements OnInit, AfterViewInit {
source share