-1
我正在開發一個應用程序,我需要使用地圖工具包(第一次),我也是iphone新手。我的要求是用戶可以編輯位置並使用引腳設置他想要的位置。我遵循很多教程,但我無法得到這個,用戶可以更改位置來移動地圖上的別針。任何幫助plz,thnx。用戶如何更改mapkit iphone dev上的位置?
我正在開發一個應用程序,我需要使用地圖工具包(第一次),我也是iphone新手。我的要求是用戶可以編輯位置並使用引腳設置他想要的位置。我遵循很多教程,但我無法得到這個,用戶可以更改位置來移動地圖上的別針。任何幫助plz,thnx。用戶如何更改mapkit iphone dev上的位置?
您可以使用UIGestureRecognizer來檢測地圖視圖上的觸摸。
在地方,你設置地圖視圖(在viewDidLoad中例如),手勢識別附加到地圖視圖:
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];
在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];
}
tnx幫助我走出困境。 – Aleem
您是否指銷釘在用戶點擊地圖? – Manali
是的,就像用戶在NY的北側(某個位置)設置的最後一個位置,如果用戶點擊東側(某個位置)NY,那麼它將使用PIN將位置改變到NY的東側,這可能嗎? – Aleem