Adding Long Press Gesture Recognizer to Google Map in iOS

ios, ios6, ios7, objective-c

Solution

You can use default MapVIew LongPress event

  /**
 * Called after a long-press gesture at a particular coordinate.
 *
 * @param mapView The map view that was pressed.
 * @param coordinate The location that was pressed.
 */
     - (void)mapView:(GMSMapView *)mapView
    didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;

Problem

I added a GMSMapView to a UIScrollView and also i added Table View to that UIScrollView. No my task is if Long Press on any Location on the Map i will get that address and add that address to Table View and also i want to add a marker at that Location. I write the Below code for adding long press gesture recognizer to the map but it is not working. ``` - (void)viewDidLoad { [super viewDidLoad]; self->map.delegate = self; CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame]; UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:fullScreenRect]; [self.view addSubview:scroll]; scroll.contentSize=CGSizeMake(320,1000); GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:21.0000 longitude:78.0000 zoom:4.5]; map = [GMSMapView mapWithFrame:CGRectMake(0,0, self.view.frame.size.width,390) camera:camera]; [scroll addSubview:map]; UITableView *tab = [[UITableView alloc]initWithFrame:CGRectMake(0, 410, self.view.bounds.size.width, 300) style:UITableViewStylePlain]; [scroll addSubview:tab]; tab.delegate = self; tab.dataSource = self; UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mapLongPress:)]; longPressGesture.minimumPressDuration = 1.5; [map addGestureRecognizer:longPressGesture]; } -(void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer { if(gestureRecognizer.state == UIGestureRecognizerStateBegan) { NSLog(@"%f",coordinate.latitude); NSLog(@"%f",coordinate.longitude); } } ``` The Main Problem here is "mapLongPress" method is not called after i long press on the MapView. Can any one Help me please.

Original source

Related problems