我真的需要一些幫助。我的反應專案不能很好地使用反應谷歌地圖。我嘗試了其他擁有它并且仍然有效的專案,但現在我正在創建一個它不起作用的新專案。每當我查看谷歌控制臺時,請求都沒有加起來,我的反應專案仍然是空白的。我也已經在 CSS 中設定了 div 的寬度到高度:100vh 和寬度:100%
組件代碼
import React, { useState, useEffect } from 'react'
import '../css/Home.css';
import { GoogleMap, withScriptjs, withGoogleMap, Marker, InfoWindow } from 'react-google-maps'
import Axios from 'axios';
function Map(){
const [coords, setcoords] = useState({ lat: "", lng: "" });
// navigator.geolocation.watchPosition((position) => {
// console.log(position);
// })
return(
<GoogleMap
defaultZoom={15}
defaultCenter={{ lat: 14.706010, lng: 121.086983 }}
>
</GoogleMap>
)
}
const WrappedMap = withScriptjs(withGoogleMap(Map));
function Home() {
return (
<div id='div_home'>
<WrappedMap
googleMapURL={`https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places&key=MY_KEY_I_JUST_REMOVED_IT`}
loadingElement={<div style={{height: '100%'}} />}
containerElement={<div style={{height: '100%'}} />}
mapElement={<div style={{height: '100%'}} />}
/>
</div>
)
}
export default Home
uj5u.com熱心網友回復:
我已經解決了我的問題。原來我有一個 react 和 react-dom v.18 的東西,我安裝了 17.0.2 版本,它完全有效!只是版本有問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/470148.html
標籤:javascript 反应 谷歌地图 反应谷歌地图
