-
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 #274 from LL08-MathematicalModelling-dowell/ft-pranai
Ft pranai
- Loading branch information
Showing
4 changed files
with
66 additions
and
150 deletions.
There are no files selected for viewing
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,40 +1,29 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { GoogleMap, LoadScript } from '@react-google-maps/api'; | ||
// src/MapComponent.js | ||
import React from 'react'; | ||
import { GoogleMap, LoadScript, MarkerF } 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]); | ||
const center = { | ||
lat: parseFloat(lat), | ||
lng: parseFloat(lng) | ||
}; | ||
|
||
return ( | ||
<LoadScript googleMapsApiKey="AIzaSyAsH8omDk8y0lSGLTW9YtZiiQ2MkmsF-uQ"> | ||
<GoogleMap | ||
mapContainerStyle={containerStyle} | ||
center={{ lat: parseFloat(lat), lng: parseFloat(lng) }} | ||
zoom={10} | ||
onLoad={(map) => (mapRef.current = { state: { map } })} | ||
/> | ||
center={center} | ||
zoom={15} | ||
> | ||
<MarkerF position={center} /> | ||
</GoogleMap> | ||
</LoadScript> | ||
); | ||
}; | ||
} | ||
|
||
export default MapComponent; |
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