Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!