2012-01-30 2 views
1

사용자가 iPhone 앱에서 위치를 선택할 수있는 응용 프로그램을 생각하고있었습니다. 나는 그것을 봤고 유용한 아무것도 찾지 못했습니다.MapView에서 위치 선택

내 질문에 사용자가 MapKit/CLLocation을 사용하여 iPhone 앱에서 위치를 선택하도록 할 수 있습니까? 그렇다면, 내가 어디에서 시작해야하는지 도와주세요.

감사합니다.

답변

2

당신은지도에 길게 누르면 제스처 인식기를 추가 할 수 있습니다 핸들 긴 프레스 법에

UILongPressGestureRecognizer* lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
lpgr.minimumPressDuration = 1.5; 
lpgr.delegate = self; 
[self.map addGestureRecognizer:lpgr]; 
[lpgr release]; 

을 CLLocationCordinate2D를 얻을 :

- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer { 
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) { 
    /* 
    Only handle state as the touches began 
    set the location of the annotation 
    */ 

    CLLocationCoordinate2D coordinate = [self.map convertPoint:[gestureRecognizer locationInView:self.map] toCoordinateFromView:self.map]; 

    [self.map setCenterCoordinate:coordinate animated:YES]; 

    // Do anything else with the coordinate as you see fit in your application 

    } 
} 
0

this SO answer을 살펴보십시오. 대답은 좌표를 얻는 방법뿐만 아니라지도에 핀 (주석)을 넣는 방법도 알려줍니다.