2011-06-24 25 views
0

我在mkmapview中添加了mkpinannotation。mkmapview上的mkpinannotation问题

我想将针脚移动到我点击mkmapview的位置。

有没有例子吗?

帮助appriciated。

+1

我认为把地图放在地图上是不好的主意。通常点击地图用于取消选择注释。您应该使用longPressGesutureRecognizer(按下时间〜1秒)以将条放置在地图上 – chatur

回答

1

首先,手势识别添加到地图视图:

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] 

     initWithTarget:self action:@selector(tapGestureHandler:)]; 

tgr.delegate = self; 

//also add 
<UIGestureRecognizerDelegate> to @interface 

[mapView addGestureRecognizer:tgr]; 

[tgr release]; 

接下来,实施shouldRecognizeSimultaneously:WithGestureRecognizer:并返回YES所以你双击手势识别器可以同时工作,作为地图的(否则轻叩引脚赢得”吨得到由地图自动处理)

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
    shouldRecognizeSimultaneouslyWithGestureRecognizer 
     :(UIGestureRecognizer *)otherGestureRecognizer 

{ 

    return YES; 
} 

最后,实现手势处理机:

- (void)tapGestureHandler:(UITapGestureRecognizer *)tgr 
{ 

    CGPoint touchPoint = [tgr locationInView:mapView]; 

    CLLocationCoordinate2D touchMapCoordinate 
     = [mapView convertPoint:touchPoint toCoordinateFromView:mapView]; 

    NSLog(@"tapGestureHandler: touchMapCoordinate = %f,%f", 
     touchMapCoordinate.latitude, touchMapCoordinate.longitude); 

} 

通过这种方式,您可以获取您在地图上触摸的位置的纬度和经度,一旦您获得了经度和纬度,您就可以轻松地将一个别针放入该位置。