tomchentw / react-google-maps

React.js Google Maps integration component

Home Page:https://tomchentw.github.io/react-google-maps/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

multiple maps on one page?

donni106 opened this issue · comments

is it possible to have multiple maps on one page?

in the body i render two maps at different places but only the second map shows up.

the map component that is used in both cases looks like:

withScriptjs(withGoogleMap((props) => (
  <GoogleMap ...>
    {props.markers.map((marker) => (
      <Marker ...>
        ...
      </Marker>
  </GoogleMap>
));    

any ideas?

@JustFly1984 thanks so far. can you show me one example with two or more maps on the same page with your library?

you can try using useLoadScript

import { GoogleMaps, useLoadScript } from "@react-google-maps/api";

 const { isLoaded, loadError } = useLoadScript({
        id: `google-map`,
        googleMapsApiKey: REACT_APP_GOOGLE_MAP_API_KEY,
         libraries: ["places"]
    });

return  isLoaded ? <GoogleMaps .../>  : <div>Loading...</div> 

In my case it works to render multiple maps
I know I'm replying late, but for someone else in the future