首页 > 解决方案 > 谷歌 api 已经出现在 react 应用程序中

问题描述

“谷歌 api 已经出现”

截图错误说明

1.

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=GOOGLE API KEY0&libraries=places"></script>
    <script>
        function init() {

            var options = {
              types: ['(cities)'],
              componentRestrictions: {country: "au"}
            };

            var input = document.getElementById('citySearch');
            var autocomplete = new google.maps.places.Autocomplete(input,options);
        }

        google.maps.event.addDomListener(window, 'load', init);
    </script>

2

  return (
    <div className="googleMapContainer">
      {console.log(window.google)}
      <LoadScript googleMapsApiKey={googleApiKey}>
        <div className="googleMap">
          <GoogleMap

如何处理?一个 api 密钥在 index.html 中,另一个正在尝试使用 api 密钥作为组件 react-google-maps 的道具

标签: reactjsapikey

解决方案


在代码中尝试<GoogleMap />不使用 2。在此处<LoadScript />查看更多信息


推荐阅读