Experience-Monks / Experience-Monks/google-maps-api
Document use of key parameter to allow choosing language served by the Google Maps API script
- Dominant language
- JavaScript
- Stars
- 33
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
The Google Maps API supports specifying a language for use with the API. This is great to prevent having multiple languages around a website, which happens when using a different language on the browser than the used on the website.
## Problem
This library currently does not _specifically_ support specifying parameters for the loaded script, [which is used to specify a language for the script](https://developers.google.com/maps/documentation/javascript/examples/map-language).
```
```
~~I have no concrete proposition on how it should be presented in this library's API, but it looks like this would be a breaking change, unless the second parameter is _type checked_ and an Object is used with a `libraries: []` key for libraries and other keys passed (sanitized?) to the URL.~~
## Solution
The `key` parameter also allows setting parameters, used mainly to allow use of enterprise accounts (See #3). Luckily, this allows us to use these keys to set a language, or any other parameters accepted on the script tag.
Instead of :
```
const mapsapi = require( 'google-maps-api' )( 'your api key', ... );
```
Use:
```
const mapsapi = require( 'google-maps-api' )( {key: 'your api key', language: "xx"}, ... );
```
## ~~Old Workaround~~
~~I'm using the fact that the libraries array is unsanitized to append my own language.~~
~~https://github.com/Jam3/google-maps-api/blob/master/index.js#L103~~
~~`mapsapiLoader(GMAPS_API_KEY, ["places","&language=xx"]);`~~
~~Though, this is as wrong as it can be! I would hazard, that while it is a bad idea, it would be better to keep this behaviour until an API breaking version is released.~~
Contributor guide
Assessment
This issue has not been assessed yet.