With the wide application of unmanned aerial systems(UAS),unmanned aerial vehicle(UAV)flight safety is becom-ing more and more prominent;In order to meet the demand of UAV cloud on the timely warning and efficient control of UAVs in air-space,a UAV geofencing algorithm is proposed;The pre-processing of the algorithm adopts the ear clipping method to triangulate the horizontal fence,constructs the triangle adjacency table,periodically detects whether the drone is within the fence during the runtime,and generates boundary violation alarms;The altitude fence is adopted to detect the altitude boundary restriction,the horizontal fence based on adjacency triangle method is used to conduct the boundary violation detection,the breadth-first search method is adopted to search for the triangular areas with the location of UAV,and the starting point of the search is based on the triangle with the last lo-cation of the UAV;The developed UAV cloud system is used to carry out the UAV horizontal uniform flight simulation;The simula-tion results show that the algorithm can quickly and accurately describe the state of the UAV violating geofence boundaries,and it is simultaneously applicable to three-dimensional geofence with keep-in and keep-out regions.