@@ -29,6 +29,13 @@ export interface GoogleMapsContextType {
29
29
map ?: google . maps . Map ;
30
30
}
31
31
32
+ // Declare global maps callback function
33
+ declare global {
34
+ interface Window {
35
+ mapsCallback : ( ) => void ;
36
+ }
37
+ }
38
+
32
39
/**
33
40
* The Google Maps context
34
41
*/
@@ -76,7 +83,7 @@ export const GoogleMapsProvider: React.FunctionComponent<
76
83
language : language || defaultLanguage ,
77
84
region : region || defaultRegion ,
78
85
...( libraries ?. length && { libraries : libraries . join ( ',' ) } ) ,
79
- ...( version && { version} ) ,
86
+ ...( version && { v : version } ) ,
80
87
...( authReferrerPolicy && { auth_referrer_policy : authReferrerPolicy } )
81
88
} ) ;
82
89
/* eslint-enable camelcase */
@@ -118,10 +125,16 @@ export const GoogleMapsProvider: React.FunctionComponent<
118
125
// Load Google Maps API
119
126
setIsLoadingAPI ( true ) ;
120
127
128
+ // Add google maps callback
129
+ window . mapsCallback = ( ) => {
130
+ apiLoadingFinished ( ) ;
131
+ } ;
132
+
133
+ params . set ( 'callback' , 'mapsCallback' ) ;
134
+
121
135
const scriptTag = document . createElement ( 'script' ) ;
122
136
scriptTag . type = 'text/javascript' ;
123
137
scriptTag . src = `${ GOOGLE_MAPS_API_URL } ?${ params . toString ( ) } ` ;
124
- scriptTag . onload = apiLoadingFinished ;
125
138
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( scriptTag ) ;
126
139
}
127
140
0 commit comments