0

Hi I got "google is not defined" this error in infobox.js, and show the error is in

infobox.prototype = new google.maps.overlayview()

Here is my code in HTML, hope I include the library right.

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="map"></div> 
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB9Mpf-bWJn8ym13pLnRdHSNHymRrvOuiw&callback=initMap">
</script>
<script src="library/infobox.js" type="text/javascript"></script> 
<script src="script.js"></script>  
</body>
</html>

I called the google map API and infobox.js in script.js file. Thanks in advance!

dididaisy
  • 141
  • 3
  • 10
  • Having both `async` and `defer` is invalid HTML anyway. – Bergi Apr 19 '16 at 11:28
  • You should [not use `new` to create prototype objects](https://stackoverflow.com/questions/12592913/what-is-the-reason-to-use-the-new-keyword-here). – Bergi Apr 19 '16 at 11:29

1 Answers1

4

When you call OverlayView constructor google map is still not loaded. Call it without async, defer and callback:

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB9Mpf-bWJn8ym13pLnRdHSNHymRrvOuiw"></script>

And it's case sensitive, therefore: infobox.prototype = new google.maps.OverlayView()

cdm
  • 1,360
  • 11
  • 18