yarn add @react-google-maps/api
import { GoogleMap, MarkerF, useJsApiLoader } from '@react-google-maps/api';
import { Spin } from 'antd';
const containerStyle = {
width: '100%',
height: '100%',
};
const center = {
lat: 40,
lng: -74,
};
function Map() {
const { isLoaded } = useJsApiLoader({
id: 'google-map-script',
googleMapsApiKey: '谷歌key',
});
return !!isLoaded ? (
<GoogleMap mapContainerStyle={containerStyle} center={center} zoom={17}>
<MarkerF
position={center}
title="marker title"
/>
</GoogleMap>
) : (
<Spin size="large" />
);
}
export default Map;
import dynamic from 'next/dynamic';
const GoogleMap = dynamic(() => import('@/Components/Map'), { ssr: false });
<div className={styles.map}>
<GoogleMap />
</div>