A closed-loop method for geosteering includes acquiring logging while drilling data and processing the logging while drilling data downhole while drilling to obtain a geosteering correction (a correction to the drilling direction based upon the LWD measurements). The geosteering correction is further processed downhole to obtain new steering tool settings which are then applied to the steering tool to change the direction of drilling. These steps are typically repeated numerous times without the need for uphole processing or surface intervention.