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

120
Visualizações
geojson not rendering in mapbox

here i am using reverse geocoding i am trying to render map of user location by sending latitude and logitude to reverse geocoding api but it is not rendring only starting coordinates used as center is rendered

import ReactDOM from "react-dom";
import React, { useRef, useEffect, useState } from "react";
import mapboxgl from "mapbox-gl";



import "./map.css";

mapboxgl.accessToken = process.env.REACT_APP_MAPBOX_ACCESS_TOKEN;

function Map() {
  const [mapData, setMapdata] = useState(null);
  const mapContainerRef = useRef(null);
  const popUpRef = useRef(new mapboxgl.Popup({ offset: 15 }));

 // initialize map when component mounts
  useEffect(() => {
    const map = new mapboxgl.Map({
      container: mapContainerRef.current,
      // See style options here: https://docs.mapbox.com/api/maps/#styles
      style: "mapbox://styles/mapbox/streets-v11",
      center: [85, 27], // starting position
      zoom: 12.5,
});

    if (navigator.geolocation) {
       navigator.geolocation.getCurrentPosition(function (position) {
        map.on("load", function () {
     
          map.addSource("myLocation", {
            type: "geojson",
            // Use a URL for the value for the `data` property.
            data:`https://api.mapbox.com/geocoding/v5/mapbox.places/${position.coords.latitude},
                  ${position.coords.longitude}.json? 
                  access_token=${process.env.REACT_APP_MAPBOX_ACCESS_TOKEN}`
          });
        });
    });
}




    // clean up on unmount
    return () => map.remove();
  }, []); 

  return <div className="map-container" ref={mapContainerRef} />;
}

export default Map;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you forgot to add the datasource to a layer. To display a source, you must add a layer and set the source attribute to your datasource.

Try adding something along the lines of:

    map.addLayer({
        id: 'locations',
        source: 'myLocation',
        // everthing beyond this point is styling/customization
        type: 'circle',
        paint: {
            'circle-color': '#ff0000',
            'circle-radius': 6,
            'circle-stroke-width': 2,
            'circle-stroke-color': '#fff'
        }
    });

More info on layers, including styling/customization can be found here: https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/

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