g.polyline.closestPointLength(point)

Return the length at which the perpendicular distance is minimized between the polyline and the given point.