Google Maps compatibility IE11 not working because

2020-06-06 02:33发布

My app website is not working fine on IE11.

The website is not loading, it gives me a blank page

This is the error thrown on IE11 :

SCRIPT5005: String expected
js (26,286)

SCRIPT5022: Exception thrown and not caught.
polyfills.js (3234,3)

I'm enclosing the screen capture on on the console

enter image description here

I have included the API in my index.html like this :

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API_KEY"></script>

It should include googlemaps after my polyfills.js, but I'm not sure on how to do that

I've tried to use agm-map, and others solutions but so far, nothing is working.

2条回答
▲ chillily
2楼-- · 2020-06-06 03:21

You could add the Google Maps script to the ngOnInit() method instead of in the tag.

let googleMapsScript = document.createElement('script')
googleMapsScript.setAttribute('src', 'https://maps.google.com/maps/api/js?v=3.38&key=YOURGOOGLEMAPSAPIKEY&libraries=places')
document.head.appendChild(googleMapsScript)

This will load the Google Maps script after the main JS for the application is loaded. I don't use Angular but a similar approach works well in VueJS.

查看更多
何必那么认真
3楼-- · 2020-06-06 03:22

I had the same issue. Not Angular but same issue.

I changed the following:

<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places,geometry"></script>

to

<script async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places,geometry"></script>

查看更多
登录 后发表回答