2011-10-18 10 views
-1

私はマップキット(初回)を使う必要があるアプリを開発していて、iphoneでも新しいアプリです。私の要件は、ユーザーがピンを使用して位置を編集し、希望の位置を設定できることです。私は多くのチュートリアルに従いますが、私はこれを得ることができませんでしたユーザーがマップ上のピンを移動する場所を変更することができます。任意のヘルプplz、thnx。ユーザーはどのようにmapkit iphone devで場所を変更できますか?

+0

ユーザーがマップをタップしたときのピンのドロップを意味しましたか? – Manali

+0

はい、ニューヨークの北側(ある場所)に設定されたユーザーの最後の場所のように、ユーザーがイーストサイド(ある場所)をクリックした場合、NYの東側の場所がピンを使用して変更されます。私を助けるために – Aleem

答えて

1

UIGestureRecognizerを使用して、マップビューのタッチを検出できます。

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] 
initWithTarget:self action:@selector(handleGesture:)]; 
tgr.numberOfTapsRequired = 2; 
tgr.numberOfTouchesRequired = 1; 
[mapView addGestureRecognizer:tgr]; 
[tgr release]; 

または長押しを使用する::

UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] 
initWithTarget:self action:@selector(handleGesture:)]; 
lpgr.minimumPressDuration = 2.0; //user must press for 2 seconds 
[mapView addGestureRecognizer:lpgr]; 
[lpgr release]; 

をあなたのセットアップ(たとえば、のviewDidLoadで)マップビュー、マップビューにジェスチャー認識を付ける代わりに

handleGesture:メソッド:

- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer 
{ 
    if (gestureRecognizer.state != UIGestureRecognizerStateEnded) 
    return; 

    CGPoint touchPoint = [gestureRecognizer locationInView:mapView]; 
    CLLocationCoordinate2D touchMapCoordinate = 
    [mapView convertPoint:touchPoint toCoordinateFromView:mapView]; 

    MKPointAnnotation *pa = [[MKPointAnnotation alloc] init]; 
    pa.coordinate = touchMapCoordinate; 
    pa.title = @"Hello"; 
    [mapView addAnnotation:pa]; 
    [pa release]; 
} 
+0

tnx。 – Aleem

関連する問題