google-maps-react icon indicating copy to clipboard operation
google-maps-react copied to clipboard

Where to Pass API Key?

Open askaper opened this issue 9 years ago • 4 comments

Before I begin, please forgive me as I'm relatively new, but...

Where does one pass the API key when using this repository? I've poured over all of the the documentation both here and on Full Stack React and see nothing regarding where to actually pass one's Google Maps API Key.

So far, the only conclusion I've come to is on line 32 of GoogleApi.js in the node modules folder where the default argument of opts.hasOwnProperty() is 'apikey'.

If anyone could tell me if I'm close or totally wrong and why I'd be most grateful. Thanks!

askaper avatar Jan 02 '17 18:01 askaper

I would like to knonw this as well. It seems that it is somehow passed in through the this.props.google item, but I am not sure what that is, or how to use it...

alexanderwhatley avatar Jan 02 '17 22:01 alexanderwhatley

There is a file in the root of the project called '.env.example'. Place your key in this file and rename to '.env'. (I have single quotes around my key but I'm not sure if that necessary.)

If you're still having trouble, check out the stand alone project in the 'GettingStarted' folder here: 'https://github.com/tzerb/google-maps-react'

tzerb avatar Jan 03 '17 01:01 tzerb

It's on README: https://github.com/fullstackreact/google-maps-react#automatically-lazy-loading-google-api

Automatically Lazy-loading Google API

The library includes a helper to wrap around the Google maps API. The GoogleApiWrapper Higher-Order component accepts a configuration object which must include an apiKey. See lib/GoogleApi.js for all >options it accepts.

import {GoogleApiWrapper} from 'GoogleMapsReactComponent'

// ...

export class Container extends React.Component {}

export default GoogleApiWrapper({
 apiKey: __GAPI_KEY__
})(Container)

The GoogleApiWrapper automatically passes the google instance loaded when the component mounts (and will only load it once).

Manually loading the Google API

If you prefer not to use the automatic loading option, you can also pass the window.google instance as a prop to your <Map /> component.

wedneyyuri avatar Jan 03 '17 11:01 wedneyyuri

Look at here

andy-pro avatar Jul 02 '17 12:07 andy-pro