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

297
Views
How to render multiple markers from an array of coordinates in react leaflet

as the title says i'm trying to render multiple markers over the map by using react leaflet. I'm gathering all the coordinates that i receive from a BE response and i put them into an array. When i render the component i only see the map without my markers. So i'm probably missing out something.

Here's my code:

var arrCoordinates = [[/* coordinates 1 */], [/* coordinates2 */]...[/* coordinates n */]]

function MultipleMarkers(){
    
    const map = useMapEvent({
        click(){
            map.locate()
        }
    })
    return arrCoordinate.map(coordinata => {
        <Marker position={coordinata}
            icon={new Icon({iconUrl: marker, iconSize: [25, 41], iconAnchor: [12, 41]})}>
            <Popup>{Object.keys(elem).length > 0 ? elem.bodyfindSegnalazione[0][0].indirizzo + ' ' + elem.bodyfindSegnalazione[0][0].civico + ' ' + elem.bodyfindSegnalazione[0][0].quartiere : ''}</Popup>
        </Marker>
    })
}
return (
    <div id="mapid" style={{display: showMap}}>
    <MapContainer 
        center={center} zoom={12} 
        scrollWheelZoom={true}
        style={{ height: "100%", width: "100%" }}
    >
        <TileLayer
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        />
        <MultipleMarkers />
        
    </MapContainer>
    </div>
);

I'll appreciate any suggestions, thanks in advance. Peace

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

0

What you are missing is the return statement before <Marker.

It should be

function MultipleMarkers() {
  const map = useMapEvent({
    click() {
      map.locate();
    }
  });

  return arrCoordinates.map((coordinata) => {
    return (
       <Marker position={coordinata}
        icon={new Icon({iconUrl: marker, iconSize: [25, 41], iconAnchor: [12, 41]})}>
        <Popup>{Object.keys(elem).length > 0 ? elem.bodyfindSegnalazione[0][0].indirizzo + ' ' + elem.bodyfindSegnalazione[0][0].civico + ' ' + elem.bodyfindSegnalazione[0][0].quartiere : ''}</Popup>
       </Marker>
    );
  });
}

Simplified example demo

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!