Igal Flegmann
Igal Flegmann

Reputation: 642

iOS Long Press is not working on Map

I am trying to get the location after a long press to dray an overlay around that location. However, the action I set on the long press is not firing.

-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];

//add the long press options

//single finger long press
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(getMapCoordinateFromTouch:)];
[longPressGesture setNumberOfTouchesRequired:1];
longPressGesture.delegate = self;
[self.mapview addGestureRecognizer:longPressGesture];

//double finger long press
UILongPressGestureRecognizer *doubleLongPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(removeBoundry:)];
[doubleLongPressGesture setNumberOfTouchesRequired:2];
doubleLongPressGesture.delegate = self;
[self.mapview addGestureRecognizer:doubleLongPressGesture];

and here is the function it calls

-(void)getMapCoordinateFromTouch:(UILongPressGestureRecognizer *) gesture{
if(gesture.state == UIGestureRecognizerStateBegan){
    CGPoint touchlocation = [gesture locationInView:self.mapview];
    pressedloc = [self.mapview convertPoint:touchlocation toCoordinateFromView:self.mapview];
    [self createBundarywithRadius:.1];    
}

Upvotes: 0

Views: 385

Answers (1)

Dominic
Dominic

Reputation: 258

Cool, so your mapview object is nil.

If you are using interface builder then you haven't attached your property to the visual component. This is basic stuff and there are loads of tutorials on how to do this kind of thing.

In short, you should already have something like:

@property (nonatomic, weak) IBOutlet MKMapView *mapview;

This isn't hooked up to the interface builder component and that is your problem!

Happy coding...

Upvotes: 1

Related Questions