-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48b1ad4
commit 22ed3b7
Showing
3 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |