从MapView中选择位置

时间:2012-01-30 18:40:49

标签: iphone objective-c xcode mapkit cllocation

我在想一个用户可以在iPhone应用程序上选择位置的应用程序。我用谷歌搜索它并没有找到任何有用的东西。

我的问题是,是否可以让用户使用MapKit / CLLocation从iphone应用程序中选择一个位置?如果是,请帮助我从哪里开始。

由于

2 个答案:

答案 0 :(得分: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

   }
}

答案 1 :(得分:0)

看看this SO answer。答案不仅告诉您如何获取坐标,还告诉您如何在地图上放置图钉(注释)。