Atlaslog
Atlaslog / Turf.js / API reference / along
Turf.js · API reference

along

Quick answer

along walks a LineString from its start by a given distance and returns the point reached, following true arc length rather than interpolating endpoints. Call turf.along(line, distance, {units: 'kilometers'}); a distance beyond the total length clamps to the final vertex.

Last verified 2026-11-03 · Turf.js 7.x · Cite this page
turf.along( line , distance , options ) → Feature<Point>
Key points
Example
var route = turf.lineString([
  [116.391263, 39.907359],   // 天安门
  [116.417600, 39.905200],   // 崇文门
  [116.455100, 39.909300]    // 国贸方向
]);

/* 线长:公里 */
var total = turf.length(route, { units: 'kilometers' });

/* 每 500 米取一个点 */
var step = 0.5;
var marks = [];
for (var d = 0; d <= total; d += step) {
  marks.push(turf.along(route, d, { units: 'kilometers' }));
}

console.log(total.toFixed(3), marks.length);
var multi = turf.multiLineString([
  [[116.39, 39.90], [116.42, 39.91]],
  [[116.42, 39.91], [116.46, 39.93]]
]);

/* 多线先合并成单线再取点 */
var merged = turf.lineString(
  multi.geometry.coordinates.reduce(function (acc, part) {
    return acc.concat(part);
  }, [])
);

var p = turf.along(merged, 1, { units: 'kilometers' });
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). along. https://www.jingweizhi.com/en/turf/api/along.html (accessed 2026-11-03).