google-maps-react icon indicating copy to clipboard operation
google-maps-react copied to clipboard

about infowindow

Open wyangwy opened this issue 6 years ago • 7 comments
trafficstars

Why doesn't my infowindow show

            <Marker
                name={'YourMarker'}
                position={{lat: this.props.lat, lng: this.props.lng}}
                icon={Images.icon_marker}
                onClick={this.onMarkerClick}
            />
            <InfoWindow
                marker={this.state.activeMarker}
                visible={this.state.showingInfoWindow}>
                <div>
                    <h1>{this.state.selectedPlace.name}</h1>
                </div>
            </InfoWindow>

onMarkerClick=(props, marker, e)=>{ this.setState({ selectedPlace: props, activeMarker: marker, showingInfoWindow: true }); }

wyangwy avatar Nov 13 '19 02:11 wyangwy

Can you provide the console output?

SimantoR avatar Dec 04 '19 19:12 SimantoR

Seems there is no problem here. Please provide your whole code.

dohahelmy avatar Dec 05 '19 12:12 dohahelmy

<InfoWindow
    marker={this.state.activeMarker}
    visible={this.state.showingInfoWindow}>
    <div>
        <h1>{this.state.selectedPlace.name}</h1>
        <button type="button" onClick={() => console.log('Custom button click!')}>TEST BUTTON</button>
    </div>
</InfoWindow>

The button click is not firing anything...

vijeeshpnfgs avatar Feb 07 '20 17:02 vijeeshpnfgs

Yeah, I can't get an InfoWindow to show up for love nor money:

const StyledMapContainer = styled.div`
  height: 100vh;
  width: 100%;
`;

const MapsLoading = () => <div>Loading...</div>

const MapContainer = ({ google, center, zoom = 14 }) => {
  const pos = { lat: center.latitude, lng: center.longitude };
  const pos2 = { lat: center.latitude + .1, lng: center.longitude };

  const markers = [<Marker
      name={'Current location'}
      title={'Location'}
      position={pos}
      key="marker-0" />,
    <Marker
      name={'Current location'}
      title={'Location'}
      position={pos2}
      key="marker-1" />,
  ]

   return <StyledMapContainer>
    <Map google={google} zoom={zoom} initialCenter={pos}>
      {markers}

      <InfoWindow marker={markers[1]} visible>
        <div>
          <h1>InfoWindow</h1>
        </div>
      </InfoWindow>
    </Map>
  </StyledMapContainer>
}

const ConnectedMapContainer = GoogleApiWrapper({
  apiKey, 
  LoadingContainer: MapsLoading,
})(MapContainer);

function App() {
  const [coords, setCoords] = useState();

  useEffect(() => {
    navigator.geolocation.getCurrentPosition(
      pos => setCoords(pos.coords)
    );
  }, []);

  return (coords ? <ConnectedMapContainer center={coords} zoom={14}></ConnectedMapContainer> : <div>Loading...</div>);
}

tomcanham avatar Feb 07 '20 19:02 tomcanham

Figured it out. Seems like we never actually call openWindow() until the visible prop changes. I think this is a bug (if you mount with visible=true, I think it should show up right away). So you can either make sure to change the prop from false to true after rendering the Map component, or I'll try to get a PR together to just call openWindow() on component mount.

tomcanham avatar Feb 07 '20 23:02 tomcanham

@vijeeshpnfgs did You manage to fire the onClick event?

lukjaki avatar May 13 '20 06:05 lukjaki

@tomcanham Did you get a chance to fix this issue?

nikhilag avatar Jul 14 '20 08:07 nikhilag