Skip to content

TypeError close(maps-api-v3/api/js/58/11a/intl/en_gb/util) #874

Closed
@benliger1987

Description

@benliger1987

I am encountering an issue with Google maps in React. The steps that are causing the above error are as follows:

  1. A modal is opened on a specific page displaying a map with a marker on it
  2. The user clicks a button and they are navigated away from the page to another
  3. The error occurs during/ after navigation
this.Eg.close is not a function. (In 'this.Eg.close()', 'this.Eg.close' is undefined)

Environment details

  1. Either Marker or Maps API
  2. Mac OS X >=10.15.7
  3. v3

Code example

const Marker: FC<google.maps.marker.AdvancedMarkerElementOptions> = (options) => {
  const [marker, setMarker] = useState<google.maps.marker.AdvancedMarkerElement>();

  useEffect(() => {
    if (marker === undefined && options.map !== undefined) {
      setMarker(new window.google.maps.marker.AdvancedMarkerElement(options));
    }
  }, [marker, options.map]);

  return null;
};

export const Map: FC<google.maps.MapOptions> = ({ center }) => {
  const ref = useRef<HTMLDivElement>(null);
  const [map, setMap] = useState<google.maps.Map>();

  const [isMakerLibraryLoaded, setIsMarkerLibraryLoaded] = useState(false);

  const isInitialized = isMakerLibraryLoaded;

  useEffect(() => {
    window.google.maps.importLibrary('marker').then(() => setIsMarkerLibraryLoaded(true));
  }, []);

  useEffect(() => {
    if (ref.current !== null && map === undefined && isInitialized) {
      setMap(
        new window.google.maps.Map(ref.current, {
          center,
          zoom: 15,
          streetViewControl: false,
          mapTypeControl: false,
          fullscreenControl: false,
          mapId: 'avhasdasd',
        })
      );
    }
  }, [map, isInitialized]);

  return (
    <div
      ref={ref}
      style={{
        width: '100%',
        height: '200px',
        marginTop: '20px',
        position: 'absolute',
        top: '-20px',
        left: 0,
      }}
    >
      {isInitialized && <Marker position={center} map={map} />}
    </div>
  );
};

Stack trace

this.Eg.close is not a function. (In 'this.Eg.close()', 'this.Eg.close' is undefined)

Screenshot 2024-11-07 184627

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions