Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda