Reactjs react-google-maps undefined

和自甴很熟 提交于 2019-12-03 15:51:08

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

If google is not defined, than you didn't load Google Maps API correctly. As explained in react-google-maps's README, put this in your HTML before your React component code loads:

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

you can also just include window reference to resolve the error, at least with default create-react-app config it does

new window.google.maps.LatLng(41.8507300, -87.6512600)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!