turf.midpoint
What is turf.midpoint?
turf.midpoint returns the geodesic midpoint between two Point features. Internally it computes the bearing and half the geodesic distance, then projects to the halfway position — so unlike a simple coordinate average, it accounts for Earth's curvature.
turf.midpoint(point1, point2) → Feature<Point>When would you use turf.midpoint?
Use turf.midpoint to place a label between two points — for example, showing distance or travel time between a user location and a selected POI anchored on the midpoint of the connecting line. It is also helpful for creating balanced camera targets when animating between two locations on MapLibre.
In Node.js, turf.midpoint is a quick way to seed synthetic test data halfway between known coordinates, or to place arrows at the midpoint of OD (origin-destination) lines in a flow map.
undefinedFAQs
Is it the same as averaging coordinates?
No — averaging [lng, lat] values drifts off the great-circle path, especially over longer distances and at high latitudes. turf.midpoint uses the geodesic formula so the result sits exactly on the great-circle arc between the inputs.
How do I install just midpoint?
npm install @turf/midpoint. It depends on @turf/distance, @turf/bearing, and @turf/destination. Tree-shaking trims unused paths in modern bundlers.
What about a rhumb-line midpoint?
Turf does not ship a dedicated rhumb-midpoint. You can approximate one with turf.rhumbDestination at half the turf.rhumbDistance on the computed turf.rhumbBearing — useful for nautical chart applications.
Can I chain this to get multiple intermediate points?
For two intermediate points use turf.midpoint twice (midpoints of each half). For many evenly spaced points, use turf.along over the LineString or call turf.lineChunk which handles segmenting cleanly.