iOS判断点是否在多边形面内(高德地图开发)

iOS判断点是否在多边形面内(高德地图开发)

2023年7月14日发(作者:)

iOS判断点是否在多边形⾯内(⾼德地图开发)定义两个属性@interface OutDoorViewController ()@property (nonatomic, strong) MAMapView *maMapView;@property (nonatomic, strong) MAPolygonView *polygonView;@end初始化指定代理⼈iew = [[MAMapView alloc] initWithFrame:]; te = self; [ addSubview:iew];构造⼀个多边形//构造多边形数据对象 CLLocationCoordinate2D coordinates[4]; coordinates[0].latitude = 39.810892; coordinates[0].longitude = 116.233413;

coordinates[1].latitude = 39.816600; coordinates[1].longitude = 116.331842;

coordinates[2].latitude = 39.762187; coordinates[2].longitude = 116.357932;

coordinates[3].latitude = 39.733653; coordinates[3].longitude = 116.278255;

MAPolygon *polygon = [MAPolygon polygonWithCoordinates:coordinates count:4]; //在地图上添加折线对象 [_maMapView addOverlay:polygon];- (MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id )overlay{ if ([overlay isKindOfClass:[MAPolygon class]]) { _polygonView = [[MAPolygonView alloc] initWithPolygon:overlay]; _dth = 5.f; _Color = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.8]; _lor = [UIColor colorWithRed:0.77 green:0.88 blue:0.94 alpha:0.8]; //连接类型 _in = kCGLineJoinMiter; return _polygonView; } return nil;}点击地图区域判断是否在范围内- (void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate{ MAMapPoint point = MAMapPointForCoordinate(coordinate); if (MAPolygonContainsPoint(point, _, 4)) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提⽰" message:@"在区域内" preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"在区域内"); }]]; [self presentViewController:alert animated:YES completion:^{ }]; }else{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提⽰" message:@"不在区域内" preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"不在区域内"); }]]; [self presentViewController:alert animated:YES completion:^{ }]; }}就可以根据在范围内和外进⾏分别的操作了end

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689266149a226501.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信