我需要一些关于如何在 iOS 地图上的标记之间添加多边形的帮助。当我在地图上使用“长按”时,它会添加一个标记,当我再放置一个标记时,它会在它们之间创建一个多边形,依此类推。
我将添加一些我的代码,希望有人可以帮助我。
#import "MWPViewController.h"
@interface MWPViewController ()
@end
@implementation MWPViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)onLongPress:(UIGestureRecognizer *)gesture
{
CGPoint coord = [gesture locationInView:self.mapView];
CLLocationCoordinate2D location = [self.mapView convertPoint:coord toCoordinateFromView:self.mapView];
CLLocation* loc = [[CLLocation alloc] initWithCoordinate:location altitude:0 horizontalAccuracy:0 verticalAccuracy:-1 timestamp:[NSDate date]];
CLGeocoder* geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark* mark = [placemarks objectAtIndex:0];
[self.mapView addAnnotation:[[MKPlacemark alloc] initWithPlacemark:mark]];
}];
}
@end