Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactjs react-google-maps undefined

I am working with the react-google-maps package https://github.com/tomchentw/react-google-maps and https://www.npmjs.com/package/react-google-maps. I have an error that says:

./src/App.js Line 31:  'google' is not defined  no-undef  Line 32:  'google' is not defined  no-undef  Line 37:  'google' is not defined  no-undef Line 42:  'google' is not defined  no-undef Line 44:  'google' is not defined  no-undef

and heres my line in the error:

 state = {
    origin: new google.maps.LatLng(41.8507300, -87.6512600),
    destination: new google.maps.LatLng(41.8525800, -87.6514100),
    directions: null,
}

componentDidMount() {
    const DirectionsService = new google.maps.DirectionsService();

    DirectionsService.route({
        origin: this.state.origin,
        destination: this.state.destination,
        travelMode: google.maps.TravelMode.DRIVING,
    }, (result, status) => {
        if (status === google.maps.DirectionsStatus.OK) {
            this.setState({
                directions: result,
            });
        } else {
            console.error(`error fetching directions ${result}`);
        }
    });
}

all the 'google' thing is error.

like image 364
Deee Avatar asked Aug 18 '17 02:08

Deee


1 Answers

the answer is I didnt include this line /* global google */ to the top of my file.

like image 63
Deee Avatar answered Sep 18 '22 20:09

Deee