Search code examples
javascriptgoogle-mapsmeteormeteor-react

dburles meteor Google Maps API error: MissingKeyMapError


I am using this Meteor package, https://github.com/dburles/meteor-google-maps-react-example/blob/master/imports/lib/GoogleMap.js

After solving my problem in Loading GoogleMaps, Google map for meteor

I encountered a new error, Google Maps API error: MissingKeyMapError

How can I solve this problem? When can I put my API credentials?


Solution

  • I'm using fullstackreact/google-maps-react

    npm install --save google-maps-react
    

    Then create a google map component.

    import React, {PropTypes} from 'react';
    import Map, {GoogleApiWrapper, Marker} from 'google-maps-react';
    
    export class Container extends React.Component {
      render() {
        if (!this.props.loaded) {
          return <div>Loading...</div>
        }
    
        return (
            <Map google={this.props.google}
              zoom={12}
              initialCenter={{lat: this.props.lat, lng: this.props.lng}}
              style={{width: '100%', height: '100%', position: 'relative'}}>
            </Map>
        )
      }
    }
    export default GoogleApiWrapper({
      apiKey: <YOUR_KEY_HERE>
    })(Container)
    

    After create above Container.jsx file, import it as a component, then use it as:

     import Container from './Container.jsx';
      ...
     <Container lat={YOUR_LAT} lng={YOUR_LNG} />
    

    This is a basic way to use the library, you can add markers, label and others. For details, kindly visit How to Write a Google Maps React Component