javascript - Reactjs react-google-maps undefined -


i working react-google-maps package https://github.com/tomchentw/react-google-maps , https://www.npmjs.com/package/react-google-maps. have error says:

./src/app.js line 31:  'google' not defined  no-undef  line 32:  'google' not defined  no-undef  line 37:  'google' not defined  no-undef line 42:  'google' not defined  no-undef line 44:  'google' not defined  no-undef 

and heres line in 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 'google' thing error.

if google not defined, didn't load google maps api correctly. explained in react-google-maps's readme, put in html before react component code loads:

<script src="https://maps.googleapis.com/maps/api/js?key=your_google_maps_api_key_goes_here"></script> 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -