0

I'm new to google maps and .env Environment variables I have this component that is rendering google maps I'm trying to set the Environment variable instead of embedding the google maps API key directly, but it's not showing up. here is my code...

import React from "react"
import {GoogleMap, LoadScript, Marker} from "@react-google-maps/api"

const MapContainer = () => {

    const mapStyles = {
        height: "50vh",
        width: "100%"
    }

    const defaultCenter = {
        lat: 40.668259, lng: -73.949158
    }


    const locations = [
        {
            name: "Brooklyn, NY",
            location: {
                lat: 40.668259,
                lng: -73.949158
            }
        }
    ]

    return (
        <LoadScript
            googleMapsApiKey={`${process.env.REACT_APP_GOOGLE_KEY}`}>
            <GoogleMap
                mapContainerStyle={mapStyles}
                zoom={13}
                center={defaultCenter}>
                {
                    locations.map(item => {
                        return (
                            <Marker key={item.name} position={item.location}/>
                        )
                    })
                }
            </GoogleMap>
        </LoadScript>
    )
}

export default MapContainer

Could somone please help me.

1 Answers1

0

Mine wasn't working either then I read the Alexei Darmin's suggestions and went to the mentioned Stackoverflow link. All it took was reading a few words at the bottom of one of the answers...run npm start after adding the .env file...yup... that did the trick.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 07 '22 at 06:58