Need help figuring out how to place a marker on a map when clicking on a location, while also deleting the previous marker. Here's the code snippet I'm working with:
const guessCoords = null;
const handleMapClick = (e) => {
let lat = e.latLng.lat();
let lng = e.latLng.lng();
guessCoords = { lat, lng };
};
function Map() {
const center = useMemo(() => ({ lat: 44, lng: -80 }), []);
return (
<GoogleMap
zoom={10}
center={center}
streetView={false}
mapTypeId="roadmap"
mapContainerClassName="w-full h-full absolute"
mapTypeControls={false}
onClick={(e) => handleMapClick(e)}
>
<Marker position={guessCoords} />
</GoogleMap>
);
}
Developing in NextJS and struggling to find a solution for my specific scenario.