Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Google map react

 {!loading ? (
        <GoogleMapReact
          defaultZoom={isEqual(latLong, USLatLong) ? 4 : 18}
          defaultCenter={latLong.lat && latLong.lng ? latLong : USLatLong}
          bootstrapURLKeys={{ key: process.env.REACT_APP_GMP_API_KEY }}
          yesIWantToUseGoogleMapApiInternals
          onGoogleApiLoaded={handleApiLoaded}
          hoverDistance={20}
          onTilesLoaded={() => setLoading(false)}
        />
      ) : (
        <Loader />)}

I have one state variable loading. If it is true then I want to show Loader. If its false then I want to show Google map.

Now problem is that, In google-map-react how can I set the variable after map loading is completed.

 const [loading, setLoading] = useState(false);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

My code looks like this.

I defined const [mapApiLoaded, setMapApiLoaded] = React.useState(false); , similar to your loading state variable.

Notice below I have an attribute onGoogleApiLoaded={({ map, maps }) => apiHasLoaded(map, maps)}. apiHasLoaded is the where I set the variable after map loading.

      <GoogleMapReact
        center={center}
        zoom={zoom}
        draggable={draggable}
        onChange={onChange}
        onChildMouseDown={onMarkerInteraction}
        onChildMouseUp={onMarkerInteractionMouseUp}
        onChildMouseMove={onMarkerInteraction}
        onChildClick={onStoreMarkerClick}
        onClick={onClick}
        bootstrapURLKeys={{
          key: process.env.REACT_APP_GOOGLE_MAP_API_KEY!,
          libraries: ["places", "geometry"],
        }}
        yesIWantToUseGoogleMapApiInternals
        onGoogleApiLoaded={({ map, maps }) => apiHasLoaded(map, maps)}
      >

And my apiHasLoaded function is defined like this:

  const apiHasLoaded = (map: any, maps: any) => {
    console.log("apiHasLoaded");
    setMapApiLoaded(true);
    setMapInstance(map);
    setMapApi(maps);
    generateAddress();
  };

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!