2014-03-28 12 views
1

GISMapView를 UIScrollView에 추가하고 해당 UIScrollView에 Table View를 추가했습니다. 지도에서 임의의 위치를 ​​길게 누르면 해당 주소를 가져 와서 해당 주소를 표보기에 추가하고 그 위치에 표식을 추가하고 싶습니다.iOS의 Google지도에 제스처 인식기를 길게 추가

길게 누르는 제스처 인식기를지도에 추가하기위한 아래 코드를 작성했지만 작동하지 않습니다.

- (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); 
    } 
    } 

여기서 주요 문제는 MapView를 길게 누르면 "mapLongPress"메서드가 호출되지 않는다는 것입니다.
아무도 도와주세요.

+0

를 사용할 수 있습니다. 이거 한번 해봐. http://stackoverflow.com/questions/1685956/uiscrollview-touchesbegan/17759373#17759373 – Rajneesh071

답변

9

당신은 기본지도보기 길게 누르 이벤트에게있는 ScrollView이 제스처에 응답하지 않기 때문에 이것이

/** 
* 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; 
+0

u r 답장을 보내 주셔서 감사합니다.하지만 작동하지 않습니다. – iSuresh

+0

map = [GMSMapView mapWithFrame : CGRectMake (0,0, self.view.frame.size.width, 390) 카메라 : 카메라]; map.delegate = 자기; –

+0

예. 일하고 있습니다. 너무 많이 감사합니다. – iSuresh

관련 문제