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

112
Vistas
react-map-gl showUserHeading not in GeolocateControl

I'm trying to display the users position and the heading indicator in React-mapbox-gl.

import * as React from "react";
import ReactMapGL, { GeolocateControl } from "react-map-gl";

const geolocateControlStyle = {
  right: 10,
  top: 10
};

function App() {
  const [viewport, setViewport] = React.useState({
    longitude: -122.45,
    latitude: 37.78,
    zoom: 14
  });
  return (
    <ReactMapGL
      {...viewport}
      width="80vw"
      height="80vh"
      onViewportChange={setViewport}
      mapboxApiAccessToken={
        "<token here>"
      }
    >
      <GeolocateControl
        style={geolocateControlStyle}
        positionOptions={{ enableHighAccuracy: true }}
        trackUserLocation={true}
        auto
      />
    </ReactMapGL>
  );
}

Currently I only have where the user is, not its current heading.

position without heading

What I want is to display the current heading, like this:,

position with heading indicatior

I've found the option for adding the heading indicator on the docs(https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol), and there's an option for showUserHeading inm the react wrapper. And I can't wrap my head around how to add this option in the react wrapper?

Here's the GeoLocation props documentation: https://visgl.github.io/react-map-gl/docs/api-reference/geolocate-control

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

EDIT: v6.1.18 is released, and the GeolocateControl now has the showUserHeading prop. Therefore the solution below is no longer needed.

I figured out that as of 21.09.2021, react-map-gl hasn't included showUserHeading within their props. I solved this by patching using this tool https://www.npmjs.com/package/patch-package

Here's the patch

diff --git a/node_modules/react-map-gl/src/components/geolocate-control.d.ts b/node_modules/react-map-gl/src/components/geolocate-control.d.ts
index 7c5d2a4..949f38b 100644
--- a/node_modules/react-map-gl/src/components/geolocate-control.d.ts
+++ b/node_modules/react-map-gl/src/components/geolocate-control.d.ts
@@ -9,6 +9,7 @@ type GeolocateControlProps = MapControlProps & Partial<{
   positionOptions: any,
   fitBoundsOptions: any,
   trackUserLocation: boolean,
+  showUserHeading?: boolean,
   showUserLocation: boolean,
   showAccuracyCircle: boolean,
   onViewStateChange?: Function,

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