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

242
Visualizações
mapbox: rehashing geoJSON after invalid response from a looped array of locations

I'm trying to get coordinates from various locations in my country to put markers+pop ups.

in some locations in my country mapbox with geoJSON forwarding gives invalid response, hence no coordinates for me.

I circumvented this by using google translate(using an npm api from @vitalets) , which usually works. so i parse the re-translated location name back to mapbox geoJSON.

but my question is how do i pass the re-translated name if it can only use it once in the forEach? should i save the name and make another geoJSON request to get the coordinates again(check out the "<<<<<<<" in the code)?

 results.forEach(myGeocoder); // results is taken from the MySQL query, bringing all the info from the list
 function myGeocoder(item,index){
        console.log("location #28:"+location[28]);
            const geoData =geocoder
                    .forwardGeocode({
                        query : item.residence,
                        autocomplete: false,
                        limit : 1
                    })
                    .send()
                    .then((response) => {
            if (
            !response ||
            !response.body ||
            !response.body.features ||
            !response.body.features.length
            ) {
            console.error('Invalid response:');// put a function for name changing here<<<<<<<<
            console.error(response);
            return;
            }
            const feature = response.body.features[0].geometry.coordinates;
            console.log("feature="+feature);
          
            longlat = feature;
         
            // updates all coordinates for all teachers
          connection.query('UPDATE list SET coordinates="'+longlat.toString()+'" WHERE list_id='+item.list_id+";", function(err,results){
                          if (err) {console.log("or not found<<<<<<<<<<<<<<<<<<<");
                         throw err;}
                          
                      })
            console.log("longlat="+longlat[0]+" ,longlat="+longlat[1])
                    }) ;
                     
                                     
    }           

my idea to get this to work, was to rehash the names , remember those that came null, and call the geoJSON again with another loop using the new translated names, and only for those.

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