iOS 百度地图判断点是否在多边形之内

是闭合区域的话,可以使用下边的方法
BMKGeometry.h
/**
*判断点是否在多边形内
*@param point 待判断的平面坐标点
*@param polygon 目标多边形的顶点数组
*@param count 目标多边形顶点数组元素个数
*@return 如果在内,返回YES,否则返回NO
*/
UIKIT_EXTERN BOOL BMKPolygonContainsPoint(BMKMapPoint point, BMKMapPoint *polygon, NSUInteger count);

/**
*判断点是否在多边形内
*@param point 待判断的经纬度点
*@param polygon 目标多边形的顶点数组
*@param count 目标多边形顶点数组元素个数
*@return 如果在内,返回YES,否则返回NO
*/
UIKIT_EXTERN BOOL BMKPolygonContainsCoordinate(CLLocationCoordinate2D point, CLLocationCoordinate2D *polygon, NSUInteger count);

判断点与圆位置关系的示例代码如下:
BOOL ptInCircle = BMKCircleContainsCoordinate(CLLocationCoordinate2DMake(39.918,116.408), CLLocationCoordinate2DMake(39.915,116.404), 1000);
除以上位置关系判断方法外,SDK还提供获取折线上与折线外指定位置最近点的方法。核心代码如下:
BMKMapPoint *polylinePoints = new BMKMapPoint[4];//这是C++的写法,下面是OC写法
//BMKMapPoint *polylinePoints = (BMKMapPoint *)malloc(sizeof(CLLocationCoordinate2D) * 4);
polylinePoints[0]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.404));
polylinePoints[1]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.915,116.454));;
polylinePoints[2]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.975,116.524));;
polylinePoints[3]= BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.855,116.554));
BMKMapPoint point = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(39.815,116.504));
BMKMapPoint nearestPoint = BMKGetNearestMapPointFromPolyline(point, polylinePoints, 4);

你可能感兴趣的:(iOS 百度地图判断点是否在多边形之内)