Optimization-Based Spatial Positioning and Energy Management for Unmanned Aerial Vehicles