Load google maps v3 dynamically with ajax

Viewed 98560

When i try to load google maps v3 with ajax the result is:

<script src="http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/8a/main.js" type="text/javascript"></script>

in the source code, i suppose that writes with javascript document.write();

how i can do this without iframe?

thanks.

8 Answers

It is now possible. See here On that page there is also a variant for manual loading, without library.

npm install @googlemaps/js-api-loader


import { Loader } from "@googlemaps/js-api-loader"


const loader = new Loader({
apiKey: "YOUR_API_KEY",
version: "weekly",
...additionalOptions,
});

loader.load().then(() => {
 map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
 center: { lat: -34.397, lng: 150.644 },
 zoom: 8,
  });
});
Related