Skip to content

Commit 4261075

Browse files
committed
docs: update readme
1 parent 2637933 commit 4261075

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

README.md

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ script.
2828

2929
## Installation
3030

31-
Install the [`@googlemaps/js-api-loader` NPM package][npm-pkg] with:
31+
Install [`@googlemaps/js-api-loader`][npm-pkg] with:
3232

3333
```sh
3434
npm install --save @googlemaps/js-api-loader
@@ -40,8 +40,6 @@ yarn add @googlemaps/js-api-loader
4040
pnpm add @googlemaps/js-api-loader
4141
```
4242

43-
### TypeScript
44-
4543
TypeScript users should additionally install the types for the Google Maps
4644
JavaScript API:
4745

@@ -73,8 +71,8 @@ importLibrary("maps").then(({ Map }) => {
7371
});
7472
```
7573

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:
7876

7977
```javascript
8078
import { setOptions, importLibrary } from "@googlemaps/js-api-loader";
@@ -92,53 +90,38 @@ await Promise.all([importLibrary("maps"), importLibrary("marker")]);
9290
## Documentation
9391

9492
This package exports just two functions, `setOptions` and `importLibrary`.
95-
The functions are available as named exports and default export.
9693

9794
```ts
9895
// Using named exports:
9996
import { setOptions, importLibrary } from "@googlemaps/js-api-loader";
10097

10198
setOptions({ key: GOOGLE_MAPS_API_KEY });
10299
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");
109100
```
110101

111102
### `setOptions(options: APIOptions): void`
112103

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.
115111

116-
Supported options:
112+
Below is a short summary of the accepted options, see the
113+
[documentation][parameters] for full descriptions and additional information:
117114

118-
- `key: string`: Your API key.
115+
- `key: string`: Your API key. This is the only required option.
119116
- `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.
142125

143126
### `importLibrary(library: string): Promise`
144127

@@ -147,9 +130,8 @@ library object when the library is loaded. In case of an error while loading
147130
the library (might be due to poor network conditions and other unforseeable
148131
circumstances), the promise is rejected with an error.
149132

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.
153135

154136
The following libraries are available:
155137

@@ -186,7 +168,7 @@ Platform [Terms of Service].
186168

187169
This library is not a Google Maps Platform Core Service. Therefore, the
188170
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
190172
in this library.
191173

192174
### European Economic Area (EEA) developers

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,6 @@ function installImportLibrary_(options: APIOptions) {
143143
if (!importLibraryExists) bootstrap(options);
144144
}
145145

146+
// export the deprecated (and non-functional) Loader class to trigger a strong
147+
// error-message for users migrating to the new version
146148
export * from "./deprecated.js";

0 commit comments

Comments
 (0)