# nearestPointOnLine

Takes a Point and a LineString and calculates the closest Point on the (Multi)LineString.


参数 类型 描述
lines (Geometry|Feature <(LineString|MultiLineString)>) lines to snap to
pt (Geometry|Feature <Point>|Array) point to snap from
options Object Optional parameters: see below


属性 类型 默认值 描述
units string kilometers can be degrees, radians, miles, or kilometers


Feature <Point> - closest point on the line to point. The properties object will contain three values: index : closest point was found on nth line part, dist : distance between pt and the closest point, location : distance along the line between start and the closest point.


var line = turf.lineString([
    [-77.031669, 38.878605],
    [-77.029609, 38.881946],
    [-77.020339, 38.884084],
    [-77.025661, 38.885821],
    [-77.021884, 38.889563],
    [-77.019824, 38.892368]
var pt = turf.point([-77.037076, 38.884017]);

var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});
Last Updated: 1/19/2021, 10:59:20 AM