Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
Drawing lines between Markers using Google-Map-React

I'd like to draw simple straight lines between multiple markers on Google Map. I render this map using google-map-react.

Map component

import { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import GoogleMapReact from 'google-map-react';
import Marker from './marker';

export default function Map() {

    const dispatch = useDispatch();
    const markers = useSelector(state => state.points);
    const [draggable, setDraggable] = useState(true);
    
    const [center, setCenter] = useState({
        lat: 59.95,
        lng: 30.33
      });
    const [zoom, setZoom] = useState(14);

    const moveMarker = (key, childProps, mouse) => {
        let markersCopy = markers;
        markersCopy.map(e => e.currPoint === key ? e.currCenter = mouse : e);
        dispatch({type: 'REORDER', payload: markersCopy});
    }

    return (
        <div style={{ height: '100vh', width: '100%' }}>
            <GoogleMapReact
                bootstrapURLKeys={{ key: process.env.REACT_APP_GOOGLE_MAPS_API_KEY }}
                defaultCenter={center}
                defaultZoom={zoom}
                onChange={(e) => dispatch({type: 'CHANGE_CURR_CENTER', payload: e.center})}
                draggable={draggable}
                onChildMouseDown={() => setDraggable(false)}
                onChildMouseUp={() => setDraggable(true)}
                onChildMouseMove={(key, childProps, mouse) => moveMarker(key, childProps, mouse)}
                >
                {markers.map(e => {
                    return (
                        <Marker
                            lat={e.currCenter.lat}
                            lng={e.currCenter.lng}
                            text={e.currPoint}
                            key={e.currPoint}
                        />
                    )
                })}
            </GoogleMapReact>
      </div>
    
    )
}

I'd like to have them connected by straight lines in the order in which they are on the list (I'm adding them to the list manually in another component). The resulting line should represent the route, the first point in the list is the beginning of the route, the last one is the end of the route. How can I achieve this?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda