Hi everyone, I have created a functionality which allows users to upload an Excel file containing addresses and I'm then geocoding those addresses to get statistics within the buffer. My issue is that the order of my addresses changes when geocoding.
document.getElementById("done-button").onclick = () => {
var fileInput = document.getElementById('fileInput');
var file = fileInput.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
var workbook = XLSX.read(data, { type: 'binary' });
var sheetName = workbook.SheetNames[0];
var sheet = workbook.Sheets[sheetName];
var dataArray = XLSX.utils.sheet_to_json(sheet, { header: 1 });
list_address = dataArray.flat()
uniqueAddressID2 = list_address
const params=[]
const geocode = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";
for (var i = 0; i < list_address.length; i++) {
//const addressinput = list_address[i]
params[i] = {
address: {
address: list_address[i],
},
countryCode: "CAN",
outSpatialReference: SpatialReference.WGS84
};
}
for (var i = 0; i < params.length; i++) {
locator.addressToLocations(geocode, params[i]).then((results) => {
if (results.length) {
const result = results[0];
const point = new Point({
x: result.location.x,
y: result.location.y,
spatialReference: { wkid: 4326 }
});
address_geo.push(point)
BatchBufferGeom(address_geo)
};
});
};
}
reader.readAsBinaryString(file);
} else {
alert('Please select a file.');
}
}