i want to use google map api in my angular web application but i have this error -> ERROR ReferenceError: google is not defined
I do everything as in the original google documentation but unfortunately it doesn't work: https://developers.google.com/maps/documentation/javascript/examples/map-simple
My TS class
/// <reference types="google.maps" />
import { Component } from '@angular/core';
import {} from 'google.maps';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'testapp';
constructor() { }
ngOnInit() {
initMap();
}
}
let map: google.maps.Map;
function initMap(): void {
map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
});
}
My html class
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<script src="./index.js"></script>
</head>
<body>
<div id="map"></div>
<!-- Async script executes immediately and must be after any DOM elements used in callback. -->
<script
src="https://maps.googleapis.com/maps/api/js?key=MyAPIKEY&callback=initMap&libraries=&v=weekly"
async
></script>
</body>
</html>