Evaluating bids

Corrigir problema com loop em Ajax

Published on the February 24, 2020 in IT & Programming

About this project

Open

Hey!

Nós estamos tendo um problema com Mapbox. Nós precisamos calcular a média de elevação baseado em algumas coordenadas. O problema abaixo parece ser mais relacionado com a lógica (calcular a média dos valores obtidos no for).

-------------------------------------------
Function getElevation(lat, lng) {
var query = "https://api.mapbox.com/v4/mapbox.mapbox-terrain-v2/tilequery/" + lat + "," + lng + ".json?layers=contour&limit=50&access_token=" + mapboxgl.accessToken;
jQuery.ajax({
method: "GET",
url: query
}).done(function(data) {
var allFeatures = data.features;
var elevations = [];

for (var i = 0; i < allFeatures.length; i++) {
elevations.push(allFeatures[i].properties.ele);
}
highestElevation = Math.max(...Elevations);

return highestElevation;
});
}
coords = [[-123.837890625,47.635783590864854],[-123.75,45.706179285330855],[-123.70605468750001,43.96119063892024],[-123.662109375,41.902277040963696],[-123.22265625000001,40.88029480552824],[-123.26660156249999,39.26628442213066],[-122.87109375,38.71980474264237],[-122.29980468749999,37.85750715625203],[-121.46484375,37.020098201368114],[-120.58593749999999,35.92464453144099],[-119.53125,34.92197103616377],[-118.3447265625,34.125447565116126]];
for (var i = 0, sum = 0; i < coords.length; i++) {
elev[i] = getElevation(coords[i][0], coords[i][1]);
}
------------------------------------------
Caso consiga corrigir o problema o mais rapido possível, envie sua proposta.

Category IT & Programming
Subcategory Web development
What is the scope of the project? Small change or bug
Is this a project or a position? Project
I currently have Not applicable
Required availability As needed
API Integrations Other (Other APIs)
Roles needed Developer

Delivery term: Not specified

Skills needed

Other projects posted by I. A.