react-wrapper icon indicating copy to clipboard operation
react-wrapper copied to clipboard

Marker is not draggable

Open patrickCode opened this issue 3 years ago • 0 comments

Issues

The marker is becoming draggable. I passed the draggable: true options when setting the marker, but the marker is being draggable

Code

import { useState, useEffect } from 'react';

function MapMarker(options) {
    const [marker, setMarker] = useState();

    useEffect(() => {
        if (!marker) {
            setMarker(new window.google.maps.Marker({draggable: true}));
        }

        // Remove marker from map on unmount
        return () => {
            if (marker) {
                marker.setMap(null);
            }
        };
    }, [marker]);

    useEffect(() => {
        if (marker) {
            marker.setOptions(options);
        }
    }, [marker, options]);

    // Since the marker is loaded in the map, null is returned from the marker component
    return null;
}

export default MapMarker;
<Wrapper apiKey="_______">
            <GoogleMap center={mapCenter} zoom={zoom}>
                <MapMarker position={mapCenter} draggable={true} />
            </GoogleMap>
        </Wrapper>

patrickCode avatar Aug 15 '22 20:08 patrickCode