JustFly1984 / react-google-maps-api

React Google Maps API
MIT License
1.82k stars 439 forks source link

[Feature Request] Handle the `auth_referrer_policy` Maps API parameter #3032

Closed ValentinDewolf closed 2 years ago

ValentinDewolf commented 2 years ago

Context

When loading the Google Maps script API, an optional auth_referrer_policy parameter can be added as specified in their documentation. This allows, if certain condition are met to avoid sharing the path to Google. Currently, the LoadScript component does not handle this parameter.

Request

Add the auth_referrer_policy to the LoadScript component to be able to load Google Maps with this parameter when specified, the following way:

  <LoadScript googleMapsApiKey="YOUR_API_KEY" authReferrerPolicy="origin">
    <GoogleMap center={center} zoom={10} />
  </LoadScript>

Current Behavior

The code above currently generates the following HTML to load the Google Maps API Script without the presence of the auth_referrer_policy URL parameter:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&v=weekly&callback=initMap" id="script-loader" async="" data-state="ready"></script>

Requested Behavior

The same code should generate the following HTML to load the Google Maps API Script with the presence of the auth_referrer_policy URL parameter:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&auth_referrer_policy=origin&v=weekly&callback=initMap" id="script-loader" async="" data-state="ready"></script>
JustFly1984 commented 2 years ago

@ValentinDewolf you can make a PR with fix, and I will release new version ASAP

You can use the hook useLoadScript instead of LoadScript, but you loose ability to switch language if you are using it.

ValentinDewolf commented 2 years ago

Hey @JustFly1984, I just created the PR here: https://github.com/JustFly1984/react-google-maps-api/pull/3035 I was able to test this locally using the storybook and worked as intended. Feel free to tell me if anything is missing

JustFly1984 commented 2 years ago

@ValentinDewolf Thank you, please test 2.12.0

ValentinDewolf commented 2 years ago

@JustFly1984 I tested the 2.12.0 on my side, it works as expected 👌