0

我正在使用谷歌地图做出反应。

我正在尝试将我的 API 中的纬度和经度数据作为标记提取到 Google 地图中。

收到错误“TypeError:markers.map 不是函数”

这是代码片段 -

  const [markers,setmarkers] = useState([]);

  const GetCoordinates = (info) => {
       setmarkers(info);} 

  function GetMaps(props){
     const AnyComponent = ({text}) => <div>{text}</div>
     defaultmarkers = {center:{lat: xxxx, lng: xxxx}, zoom: 10}
   }

   return (<div style={{height:'100vh', width:'100vw' }}>
     <GoogleMapReact
       bootstrapURLKeys = xxxxxx
       defaultcenter= {defaultmarkers.center}
       defaultZoom= {defaultmarkers.zoom}>

       <AnyComponent>
          <ul>
           {markers.map(x => (   //////getting error on this line
            <li key={x.id}>
               lat={x.lat}  // pull from API data
               lng={x.lng} // pull info from API
               text={x.title}
              </li>))}</ul>
       </AnyComponent><GoogleMapReact>

       <GetMaps /> // function called in return tag

收到错误“TypeError:markers.map 不是函数”

4

0 回答 0