Skip to content

Commit

Permalink
Google maps working
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBeast229 committed Jan 21, 2024
1 parent 48b1ad4 commit 22ed3b7
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 17 deletions.
89 changes: 89 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@react-google-maps/api": "^2.19.2",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@vis.gl/react-google-maps": "^0.5.0",
"moment": "^2.30.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
68 changes: 51 additions & 17 deletions src/Maps.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
import React from 'react';
import Map from './GoogleMap';
import React from 'react'
import { GoogleMap, useJsApiLoader } from '@react-google-maps/api';

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

function Maps() {
return <div>
<h2> Maps Page </h2>
</div>
}
const center = {
lat: -3.745,
lng: -38.523
};

function MyComponent() {
const { isLoaded } = useJsApiLoader({
id: 'google-map-script',
googleMapsApiKey: "AIzaSyDt_et4e5arhJOr4b-DGh3gBJW961RwHnc"
})

const [map, setMap] = React.useState(null)

const onLoad = React.useCallback(function callback(map) {
const bounds = new window.google.maps.LatLngBounds(center);
map.fitBounds(bounds);

setMap(map)
}, [])

const onUnmount = React.useCallback(function callback(map) {
setMap(null)
}, [])

return isLoaded ? (
<div style = {{

width: "100%",
height: "100vh",
background:"red",
display: "flex",
justifyContent: "center",
alignItems: "end"

function App() {
return (
<div style={{ height: '500px', width: '100%' }}>
<Map
containerElement={<div style={{ height: '100%' }} />}
mapElement={<div style={{ height: '100%' }} />}
/>
</div>
);
}}>
<GoogleMap
mapContainerStyle={containerStyle}
center={center}
zoom={10}
onLoad={onLoad}
onUnmount={onUnmount}
>
{ /* Child components, such as markers, info windows, etc. */ }
<></>
</GoogleMap>
</div>
) : <></>
}

export default App;
export default React.memo(MyComponent)

0 comments on commit 22ed3b7

Please sign in to comment.