2012-01-30 84 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。答案不僅告訴你如何獲得座標,而且還告訴你如何在地圖上放置圖釘(註釋)。