In this paper, the deployment of an unmanned aerial vehicle (UAV) as a flying base station used to provide on the fly wireless communications to a given geographical area is analyzed. In particular, the co-existence between the UAV, that is transmitting data in the downlink, and an underlaid device-todevice (D2D) communication network is considered. For this model, a tractable analytical framework for the coverage and rate analysis is derived. Two scenarios are considered: a static UAV and a mobile UAV. In the first scenario, the average coverage probability and the average sum-rate for the users in the area are derived as a function of the UAV altitude and the number of D2D users. In the second scenario, using the disk covering problem, the minimum number of stop points that the UAV needs to visit in order to completely cover the area is computed. Simulation and analytical results show that, depending on the density of D2D users, optimal values for the UAV altitude exist for which the average sum-rate and the coverage probability are maximized. Moreover, our results also show that, by enabling the UAV to intelligently move over the target area, the overall communication rate and coverage probability can be significantly improved. Finally, in order to provide a full coverage for the area of interest, the tradeoff between the coverage and delay, in terms of the number of stop points, is discussed.