code: public static GeometryLocation getVertexToSnap(Geometry g, Point p, double tolerance) {
          DistanceOp distanceOp = new DistanceOp(g, p);
          GeometryLocation snapedPoint = distanceOp.nearestLocations()[0];
          if (tolerance == 0 || snapedPoint.getCoordinate().distance(p.getCoordinate()) <= tolerance) {
              return snapedPoint;
          }
          return null;
  
      }
docs: Gets the coordinate of a Geometry that is the nearest of a given Point,
  with a distance tolerance.
  
  @param g
  @param p
  @param tolerance
  @return