0

私は iOS 6 マップキットを使用しています。タップした場所の座標を取得して NSLog に記録し、表示できるようにする必要があります。誰かがこれを行う方法についてのばかガイドを教えてもらえますか? 私は多くの投稿を見てきましたが、機能する投稿は1つも見つかりませんでした。

前もって感謝します、

イーサン

4

1 に答える 1

0

次のような適切なプロパティに接続されたマップ ビューがあるとします。

@property (weak) IBOutlet MKMapView *mapView;
...
@synthesize mapView;

これを次の場所に入れることができますviewDidLoad:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[mapView addGestureRecognizer:singleTap];

次に、この関数をコントローラーに追加します。

- (void)handleSingleTap:(UIGestureRecognizer *)sender
{
    CLLocationCoordinate2D coord = [mapView convertPoint:[sender locationInView:mapView] toCoordinateFromView:mapView];
    NSLog(@"Map touched %f, %f.", coord.latitude, coord.longitude);
}

ちなみに、これはすべてARCを使用しています。

于 2013-06-18T08:28:09.047 に答える