在iOS中的地图上添加多边形

时间:2013-11-28 11:03:07

标签: ios objective-c mkmapview uigesturerecognizer mkpolygon

我需要一些关于如何在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

0 个答案:

没有答案