@@ -28,7 +28,7 @@ script.
28
28
29
29
## Installation
30
30
31
- Install the [ ` @googlemaps/js-api-loader ` NPM package ] [ npm-pkg ] with:
31
+ Install [ ` @googlemaps/js-api-loader ` ] [ npm-pkg ] with:
32
32
33
33
``` sh
34
34
npm install --save @googlemaps/js-api-loader
@@ -40,8 +40,6 @@ yarn add @googlemaps/js-api-loader
40
40
pnpm add @googlemaps/js-api-loader
41
41
```
42
42
43
- ### TypeScript
44
-
45
43
TypeScript users should additionally install the types for the Google Maps
46
44
JavaScript API:
47
45
@@ -73,8 +71,8 @@ importLibrary("maps").then(({ Map }) => {
73
71
});
74
72
```
75
73
76
- If you use web components from the Google Maps JavaScript API (e.g. ` gmp-map ` ,
77
- and ` gmp-advanced-marker ` ), you need to import them as well:
74
+ If you use custom HTML elements from the Google Maps JavaScript API (e.g.
75
+ ` <gmp-map> ` , and ` < gmp-advanced-marker> ` ), you need to import them as well:
78
76
79
77
``` javascript
80
78
import { setOptions , importLibrary } from " @googlemaps/js-api-loader" ;
@@ -92,53 +90,38 @@ await Promise.all([importLibrary("maps"), importLibrary("marker")]);
92
90
## Documentation
93
91
94
92
This package exports just two functions, ` setOptions ` and ` importLibrary ` .
95
- The functions are available as named exports and default export.
96
93
97
94
``` ts
98
95
// Using named exports:
99
96
import { setOptions , importLibrary } from " @googlemaps/js-api-loader" ;
100
97
101
98
setOptions ({ key: GOOGLE_MAPS_API_KEY });
102
99
await importLibrary (" core" );
103
-
104
- // Using the default export:
105
- import MapsAPILoader from " @googlemaps/js-api-loader" ;
106
-
107
- MapsAPILoader .setOptions ({ key: GOOGLE_MAPS_API_KEY });
108
- await MapsAPILoader .importLibrary (" core" );
109
100
```
110
101
111
102
### ` setOptions(options: APIOptions): void `
112
103
113
- Sets the options for loading the Google Maps JavaScript API. See the
114
- [ documentation] [ parameters ] for additional information.
104
+ Sets the options for loading the Google Maps JavaScript API and installs the
105
+ global ` google.maps.importLibrary ` function that is used by the importLibrary
106
+ function.
107
+
108
+ This function should be called as early as possible in your application and
109
+ should only be called once. Any further calls will not have any effect and
110
+ log a warning to the console.
115
111
116
- Supported options:
112
+ Below is a short summary of the accepted options, see the
113
+ [ documentation] [ parameters ] for full descriptions and additional information:
117
114
118
- - ` key: string ` : Your API key.
115
+ - ` key: string ` : Your API key. This is the only required option.
119
116
- ` v: string ` : The version of the Maps JavaScript API to load.
120
- - ` language: string ` : The language to use. This affects the names of
121
- controls, copyright notices, driving directions, and control labels, and
122
- the responses to service requests.
123
- - ` region: string ` : The region code to use. This alters the API's behavior
124
- based on a given country or territory.
125
- - ` libraries: string[] ` : An array of additional Maps JavaScript API libraries to
126
- load. Specifying a fixed set of libraries is not generally recommended, but is
127
- available for developers who want to finely tune the caching behavior on their
128
- website.
129
- - ` authReferrerPolicy: string ` : Can be used to configure HTTP Referrer
130
- Restrictions in the Cloud Console to limit which URLs are allowed to use a
131
- particular API Key.
132
- - ` mapIds: string[] ` : An array of map IDs. Causes the configuration for the
133
- specified map IDs to be preloaded. Specifying map IDs here is not required
134
- for map IDs usage, but is available for developers who want to finely tune
135
- network performance.
136
- - ` channel: string ` : Can be used to track your usage using numeric channels.
137
- Only numeric values ` 0 ` to ` 999 ` are allowed.
138
- - ` solutionChannel ` : Google Maps Platform provides many types of sample code to
139
- help you get up and running quickly. To track adoption of our more complex
140
- code samples and improve solution quality, Google includes the solutionChannel
141
- query parameter in API calls in our sample code.
117
+ - ` language: string ` : The language to use.
118
+ - ` region: string ` : The region code to use.
119
+ - ` libraries: string[] ` : additional libraries to load.
120
+ - ` authReferrerPolicy: string ` : Set the referrer policy for the API requests.
121
+ - ` mapIds: string[] ` : An array of map IDs to preload.
122
+ - ` channel: string ` : Can be used to track your usage.
123
+ - ` solutionChannel ` : Used by the Google Maps Platform to track adoption and
124
+ usage of examples and solutions.
142
125
143
126
### ` importLibrary(library: string): Promise `
144
127
@@ -147,9 +130,8 @@ library object when the library is loaded. In case of an error while loading
147
130
the library (might be due to poor network conditions and other unforseeable
148
131
circumstances), the promise is rejected with an error.
149
132
150
- Calling this function for the first time will trigger loading the maps API
151
- itself. After that, the options can no longer be changed, and trying to do
152
- that will log a warning to the console.
133
+ Calling this function for the first time will trigger loading the Google
134
+ Maps JavaScript API itself.
153
135
154
136
The following libraries are available:
155
137
@@ -186,7 +168,7 @@ Platform [Terms of Service].
186
168
187
169
This library is not a Google Maps Platform Core Service. Therefore, the
188
170
Google Maps Platform Terms of Service (e.g. Technical Support Services,
189
- Service Level Agreements, and Deprecation Policy) don’t apply to the code
171
+ Service Level Agreements, and Deprecation Policy) do not apply to the code
190
172
in this library.
191
173
192
174
### European Economic Area (EEA) developers
0 commit comments