Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] unable to zoom in, zoom out, or drag the map #223

Closed
abhishekmardiya opened this issue Feb 16, 2024 · 3 comments
Closed

[Bug] unable to zoom in, zoom out, or drag the map #223

abhishekmardiya opened this issue Feb 16, 2024 · 3 comments

Comments

@abhishekmardiya
Copy link

abhishekmardiya commented Feb 16, 2024

Description

unable to zoom in, zoom out, or drag the map.

Steps to Reproduce

Whole Code

import {
  APIProvider,
  InfoWindow,
  Map,
  Marker,
  useMarkerRef,
} from "@vis.gl/react-google-maps";
import { useState } from "react";

interface Props {
  lat: number;
  lng: number;
  fullAddress: string;
}

export const GoogleMap = ({ lat, lng, fullAddress }: Props) => {
  const position = { lat, lng };

  const [markerRef, marker] = useMarkerRef();
  const [isInfoWindowOpen, setIsInfoWindowOpen] = useState(true);

  const toggleInfoWindowStatus = (state?: boolean) =>
    setIsInfoWindowOpen((previousState) => !previousState);

  return (
    <APIProvider
      apiKey={process?.env?.NEXT_PUBLIC_GOOGLE_MAP_API_KEY as string}
    >
      <Map
        center={position}
        zoom={14}
        className="h-60 w-full rounded-md border border-C_E1E1E1"
      >
        <Marker
          position={position}
          ref={markerRef}
          onClick={() => toggleInfoWindowStatus(true)}
        />
        {isInfoWindowOpen && (
          <InfoWindow
            anchor={marker}
            onCloseClick={() => toggleInfoWindowStatus(false)}
          >
            <span className="line-clamp-2 break-words">{fullAddress}</span>
          </InfoWindow>
        )}
      </Map>
    </APIProvider>
  );
};

Environment

  • Library version: @vis.gl/react-google-maps: 0.6.1
  • Browser and Version: Chrome
  • OS: Windows

Logs

NA
@abhishekmardiya abhishekmardiya added the bug Something isn't working label Feb 16, 2024
@usefulthink
Copy link
Collaborator

That was a recent change we did to the API, we are now using center/defaultCenter props like React-form elements. If you don't want to deal with the state, you can use defaultCenter/defaultZoom. See here: https://visgl.github.io/react-google-maps/docs/api-reference/components/map#controlled-and-uncontrolled-props

@usefulthink
Copy link
Collaborator

(feel free to reopen if that doesn't solve your issue)

@usefulthink usefulthink removed the bug Something isn't working label Feb 16, 2024
@abhishekmardiya
Copy link
Author

Thanks a lot. It worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants