Skip to content

Commit

Permalink
[feat] added google maps to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tam33 committed Oct 6, 2024
1 parent 0656561 commit 58419e2
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"pre-commit": "(pnpm run tsc || true) && (pnpm run lint || true) && pnpm run prettier"
},
"dependencies": {
"@googlemaps/js-api-loader": "^1.16.8",
"@googlemaps/markerclusterer": "^2.5.3",
"@react-google-maps/api": "^2.19.3",
"next": "^14.2.13",
"react": "^18",
"react-dom": "^18"
Expand Down
80 changes: 68 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 45 additions & 1 deletion src/app/components/map.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
import { Loader } from '@googlemaps/js-api-loader';
'use client';

import { useCallback, useState } from 'react';
import { GoogleMap, useJsApiLoader } from '@react-google-maps/api';

const containerStyle = {
width: '700px',
height: '700px',
};

const center = {
lat: 40.7128,
lng: -74.006,
};

const zoom = 7;

export default function Map() {
const { isLoaded } = useJsApiLoader({
id: 'google-map-script',
googleMapsApiKey: process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY as string,
});

const [map, setMap] = useState<google.maps.Map | null>(null);

const onLoad = useCallback((map: google.maps.Map) => {
map.setCenter(center);
map.setZoom(zoom);
setMap(map);
}, []);

const onUnmount = useCallback(() => {
setMap(null);
}, []);

return isLoaded ? (
<GoogleMap
mapContainerStyle={containerStyle}
onLoad={onLoad}
onUnmount={onUnmount}
></GoogleMap>
) : (
<></>
);
}
4 changes: 2 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CSSProperties } from 'react';
import Image from 'next/image';
import BPLogo from '@/assets/images/bp-logo.png';
import Map from './components/map';

export default function Home() {
return (
<main style={mainStyles}>
<Image style={imageStyles} src={BPLogo} alt="Blueprint Logo" />
<p>Open up app/page.tsx to get started!</p>
<Map />
</main>
);
}
Expand Down

0 comments on commit 58419e2

Please sign in to comment.