-
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.
Merge pull request #272 from LL08-MathematicalModelling-dowell/fronte…
…nd-Norah Frontend norah
- Loading branch information
Showing
6 changed files
with
246 additions
and
35 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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { GoogleMap, LoadScript } from '@react-google-maps/api'; | ||
|
||
const containerStyle = { | ||
width: '100%', | ||
height: '100%' | ||
}; | ||
|
||
const MapComponent = ({ lat, lng }) => { | ||
const mapRef = useRef(null); | ||
|
||
useEffect(() => { | ||
const initializeMap = async () => { | ||
if (mapRef.current && window.google) { | ||
const { AdvancedMarkerElement } = window.google.maps.marker; | ||
|
||
const map = mapRef.current.state.map; | ||
new AdvancedMarkerElement({ | ||
position: { lat: parseFloat(lat), lng: parseFloat(lng) }, | ||
map: map, | ||
}); | ||
} | ||
}; | ||
|
||
initializeMap().catch((error) => console.error('Error loading Google Maps:', error)); | ||
}, [lat, lng]); | ||
|
||
return ( | ||
<LoadScript googleMapsApiKey="AIzaSyAsH8omDk8y0lSGLTW9YtZiiQ2MkmsF-uQ"> | ||
<GoogleMap | ||
mapContainerStyle={containerStyle} | ||
center={{ lat: parseFloat(lat), lng: parseFloat(lng) }} | ||
zoom={10} | ||
onLoad={(map) => (mapRef.current = { state: { map } })} | ||
/> | ||
</LoadScript> | ||
); | ||
}; | ||
|
||
export default MapComponent; |
Oops, something went wrong.