Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

missing data added between two points javascript

var latA=32.718835,
    lonA=-16.761171,
    latB=32.711461,
    lonB=-16.911347,
    lat = Math.floor(latA * 1e6), // use integers
    lon = Math.floor(lonA * 1e6),
    countLat = Math.floor(Math.abs(latA-latB)*1e6)+1,
    countLon = Math.floor(Math.abs(lonA-lonB)*1e6)+1,
    count = Math.max(countLat, countLon), // change to Math.min to use least number of points
    lonDiff = (lonB-lonA) / countLat * 1e6,
    latDiff = (latB-latA) / countLon * 1e6,
    latSign = Math.sign(latB - latA),
    lonSign = Math.sign(lonB - lonA),
    arr = [];
    
if (countLat < countLon) { // change to > to use least number of points
    lonDiff = lonSign;
} else {
    latDiff = latSign;
}
    
for (let i = 0; i <= count; i++) {
    arr.push({
        lat: (lat / 1e6).toFixed(6),
        lon: (lon / 1e6).toFixed(6)
    });
    lat += latDiff;
    lon += lonDiff;
    
}
console.log(arr.length, arr[0], arr.slice(-1)[0]);
Comment

PREVIOUS NEXT
Code Example
Javascript :: add class to random element 
Javascript :: redux acions 
Javascript :: adding preview images to react apps for linkedin 
Javascript :: nodejs store selected dropdown in variable 
Javascript :: how er create json data file to train our rasa model 
Javascript :: how to eat beans in javascirpt 
Javascript :: pebbel if statement check boolean 
Javascript :: jest check array of objects 
Javascript :: discord.js bot credits command 
Javascript :: how to send array to js file in wplms 
Javascript :: connect react native app to local api macos 
Javascript :: know if a mobile open the website js 
Javascript :: draw diamond in typescript 
Javascript :: Uncaught TypeError: jQuery.browser is undefined 
Javascript :: left_field in jsgrid 
Javascript :: chrome extension how to save data to an alternative file 
Javascript :: can i use hooks with expo in react native 
Javascript :: show image in popup from owl carousel pop up 
Javascript :: react cam filters 
Javascript :: what is code.jquery integrity crossorigin 
Javascript :: javascript canvas clip rectangle 
Javascript :: sort callback function 
Javascript :: how to compare a string with its ending in javascript 
Javascript :: react native app slow lagging image 
Javascript :: how to use getBackgroundPage 
Javascript :: set in Dynamo DB not properly incrementing nodejs lamnda function 
Javascript :: ESX.Math.Round 
Javascript :: 4. You want to print the incremental count each time you instantiate a object using new in JS 
Javascript :: customize please select some product options before wordpress message 
Javascript :: puppeteer wait for select[name= 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =