showing results for - "missing data added between two points javascript"
Cristina
07 Jun 2019
1var latA=32.718835,
2    lonA=-16.761171,
3    latB=32.711461,
4    lonB=-16.911347,
5    lat = Math.floor(latA * 1e6), // use integers
6    lon = Math.floor(lonA * 1e6),
7    countLat = Math.floor(Math.abs(latA-latB)*1e6)+1,
8    countLon = Math.floor(Math.abs(lonA-lonB)*1e6)+1,
9    count = Math.max(countLat, countLon), // change to Math.min to use least number of points
10    lonDiff = (lonB-lonA) / countLat * 1e6,
11    latDiff = (latB-latA) / countLon * 1e6,
12    latSign = Math.sign(latB - latA),
13    lonSign = Math.sign(lonB - lonA),
14    arr = [];
15    
16if (countLat < countLon) { // change to > to use least number of points
17    lonDiff = lonSign;
18} else {
19    latDiff = latSign;
20}
21    
22for (let i = 0; i <= count; i++) {
23    arr.push({
24        lat: (lat / 1e6).toFixed(6),
25        lon: (lon / 1e6).toFixed(6)
26    });
27    lat += latDiff;
28    lon += lonDiff;
29    
30}
31console.log(arr.length, arr[0], arr.slice(-1)[0]);