Skip to content

Commit 7aec615

Browse files
committed
docs: update readme
1 parent f1ce754 commit 7aec615

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

README.md

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ importLibrary("maps").then(({ Map }) => {
7171
});
7272
```
7373

74-
If you use custom HTML element from the Google Maps JavaScript API (e.g. `<gmp-map>`,
75-
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:
7676

7777
```javascript
7878
import { setOptions, importLibrary } from "@googlemaps/js-api-loader";
@@ -90,53 +90,38 @@ await Promise.all([importLibrary("maps"), importLibrary("marker")]);
9090
## Documentation
9191

9292
This package exports just two functions, `setOptions` and `importLibrary`.
93-
The functions are available as named exports and default export.
9493

9594
```ts
9695
// Using named exports:
9796
import { setOptions, importLibrary } from "@googlemaps/js-api-loader";
9897

9998
setOptions({ key: GOOGLE_MAPS_API_KEY });
10099
await importLibrary("core");
101-
102-
// Using the default export:
103-
import MapsAPILoader from "@googlemaps/js-api-loader";
104-
105-
MapsAPILoader.setOptions({ key: GOOGLE_MAPS_API_KEY });
106-
await MapsAPILoader.importLibrary("core");
107100
```
108101

109102
### `setOptions(options: APIOptions): void`
110103

111-
Sets the options for loading the Google Maps JavaScript API. See the
112-
[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.
113111

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

116-
- `key: string`: Your API key.
115+
- `key: string`: Your API key. This is the only required option.
117116
- `v: string`: The version of the Maps JavaScript API to load.
118-
- `language: string`: The language to use. This affects the names of
119-
controls, copyright notices, driving directions, and control labels, and
120-
the responses to service requests.
121-
- `region: string`: The region code to use. This alters the API's behavior
122-
based on a given country or territory.
123-
- `libraries: string[]`: An array of additional Maps JavaScript API libraries to
124-
load. Specifying a fixed set of libraries is not generally recommended, but is
125-
available for developers who want to finely tune the caching behavior on their
126-
website.
127-
- `authReferrerPolicy: string`: Can be used to configure HTTP Referrer
128-
Restrictions in the Cloud Console to limit which URLs are allowed to use a
129-
particular API Key.
130-
- `mapIds: string[]`: An array of map IDs. Causes the configuration for the
131-
specified map IDs to be preloaded. Specifying map IDs here is not required
132-
for map IDs usage, but is available for developers who want to finely tune
133-
network performance.
134-
- `channel: string`: Can be used to track your usage using numeric channels.
135-
Only numeric values `0` to `999` are allowed.
136-
- `solutionChannel`: Google Maps Platform provides many types of sample code to
137-
help you get up and running quickly. To track adoption of our more complex
138-
code samples and improve solution quality, Google includes the solutionChannel
139-
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.
140125

141126
### `importLibrary(library: string): Promise`
142127

@@ -146,8 +131,7 @@ the library (might be due to poor network conditions and other unforseeable
146131
circumstances), the promise is rejected with an error.
147132

148133
Calling this function for the first time will trigger loading the maps API
149-
itself. After that, the options can no longer be changed, and trying to do
150-
that will log a warning to the console.
134+
itself.
151135

152136
The following libraries are available:
153137

0 commit comments

Comments
 (0)