Asteroid detections in astronomical images may appear as trails due to a combination of their apparent rate of motion and exposure duration. Nearby asteroids in particular typically have high apparent rates of motion and acceleration. Their recovery, especially on their discovery apparition, depends upon obtaining good astrometry from the trailed detections. We present an analytic function describing a trailed detection under the assumption of a Gaussian point spread function (PSF) and constant rate of motion. We have fit the function to both synthetic and real trailed asteroid detections from the Pan-STARRS1 survey telescope to obtain accurate astrometry and photometry. For short trails our trailing function yields the same astrometric and photometry accuracy as a functionally simpler 2-d Gaussian but the latter underestimates the length of the trail - a parameter that can be important for measuring the objects rate of motion and assessing its cometary activity. For trails longer than about 10 pixels (> 3xPSF) our trail fitting provides 3-times better astrometric accuracy and up to 2 magnitudes improvement in the photometry. The trail fitting algorithm can be implemented at the source detection level for all detections to provide trail length and position angle that can be used to reduce the false tracklet rate.