Search code examples
coordinatesmapboxlatitude-longitudeturfjs

How can i generate points between two longitudes and latitudes using turfjs library


I want to simulate moving dorne on the MAP. In order to do that, I would like to send drones current longitude and latitude using socket.io. Just for simulation, because in production data will come through the socket.

Problem

I have two longitude and latitude points on the map. Now, I want to generate some points on the line that is made by adding both points, so I can send them through socket at some time interval.

I tried to use https://turfjs.org/ to do that. I was thinking that I can use Line chunk.

When I checked its returned value, then I found that it is a collection of LineStrings.

I don't understand what it means by line chunk here, whether I can use its coordinates to create a line or not.

What i need

I have two points:

A = [lon1,lat1] B = [lon2,lat2]

I need this

[
[lon1,lat1]
// some more points
[lon2,lat2]
]

Solution

  • use

    var linePoint = turf.lineString([[-95, 40], [-93, 45]]);
    var options = {units: 'kilometers'};
    
    var along = turf.along(linePoint, 100, options);
    // at distance of 100KM from first point  towards second point