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

240
Vistas
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 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