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

174
Views
Array.map doesn't render Google Maps Markers in react

I am building a react application where a user can add markers to a GoogleMaps map by clicking on it. The problem is, when I click the map, the point is added to the array, but the marker is not rendered.For some reason, and the function inside the map is only called once, when the map is firstly displayed.

import { useAuth } from "../contexts/AuthContext";
import Navbar from "./Navbar";
import { useJsApiLoader, GoogleMap, Marker } from '@react-google-maps/api'
import { Box } from '@chakra-ui/react';
import { useState } from 'react';
import LoadingCircle from "./LoadingCircle";

export default function MapPage() {

const center = { lat: 50.45, lng: 30.52 };
const { loading, currentUser } = useAuth();
const { isLoaded } = useJsApiLoader({
    googleMapsApiKey: process.env.REACT_APP_GOOGLE_MAPS_API_KEY,
    libraries: ['places']
});

const [map, setMap] = useState(null);
const [points, setPoints] = useState([center]);
console.log(process.env.REACT_APP_GOOGLE_MAPS_API_KEY)

if (!isLoaded) {
    return (
        <div>
        <Navbar></Navbar>
            <LoadingCircle />
        </div>
    );
}

return (
    <div>
        <Navbar></Navbar>
        <div className="">
            <Box position={'relative'} top={0} left={0} h="93.5vh" w="100%" className="h-full w-full">
                <GoogleMap 
                    center={center}
                    zoom={15} 
                    mapContainerStyle={{ width: '100%', height: '100%' }}
                    options={{
                        zoomControl: false,
                        streetViewControl: false,
                        mapTypeControl: false,
                        fullscreenControl: false,
                    }}
                    onLoad={(map) => setMap(map)}
                    onClick={e => {
                        let lat = e.latLng.lat();
                        let lng = e.latLng.lng();
                        let new_point = { lat: lat, lng: lng };
                        let new_points = points;
                        new_points.push(new_point);
                        setPoints(new_points);
                        setMap(map);
                        console.log(points);
                    }}>
                        {
                            points.map((point, index) => {
                                console.log(point);
                                console.log(index);
                                return <Marker position={point}/> 
                            })
                        }
                </GoogleMap>
            </Box>               
        </div>

    </div>
);

}

about 4 years ago · Juan Pablo Isaza
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!