사용자가지도를 두드려 위치를 선택할 수 있도록 mkmapview에 mkannotation을 추가하고 싶습니다.터치 맵에 mkannotation 추가
나는 드래그에 대해 읽었습니다 & 드롭 그러나 당신이 단계적으로 핀을 이동해야하기 때문에 당신이 도시의 다른 구석으로 이동하려는 경우 조금 짜증나.
사용자가 내 핀을 두드리고 움직일 때 좌표를 얻으려면 어떻게해야합니까?
감사합니다.
사용자가지도를 두드려 위치를 선택할 수 있도록 mkmapview에 mkannotation을 추가하고 싶습니다.터치 맵에 mkannotation 추가
나는 드래그에 대해 읽었습니다 & 드롭 그러나 당신이 단계적으로 핀을 이동해야하기 때문에 당신이 도시의 다른 구석으로 이동하려는 경우 조금 짜증나.
사용자가 내 핀을 두드리고 움직일 때 좌표를 얻으려면 어떻게해야합니까?
감사합니다.
UITapGestureRecognizer
을 사용하면 CGPoint
과 탭 포인트 좌표를 얻을 수 있습니다.
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addPin:)];
[recognizer setNumberOfTapsRequired:1];
[map addGestureRecognizer:recognizer];
[recognizer release];
는이 조각 사용할 수있는 대상 조치를
- (void)addPin:(UITapGestureRecognizer*)recognizer
{
CGPoint tappedPoint = [recognizer locationInView:map];
NSLog(@"Tapped At : %@",NSStringFromCGPoint(tappedPoint));
CLLocationCoordinate2D coord= [map convertPoint:tappedPoint toCoordinateFromView:map];
NSLog(@"lat %f",coord.latitude);
NSLog(@"long %f",coord.longitude);
// add an annotation with coord
}
에 IOS < 3.2,을 추가
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (touch.tapCount == 1) {
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([map frame], [touch locationInView:self.view]))
{
CLLocationCoordinate2D coord=
[map convertPoint:tappedPoint toCoordinateFromView:map];
NSLog(@"lat %f",coord.latitude);
NSLog(@"long %f",coord.longitude);
// add an annotation with coord
// or (as example before)
// [self addPin];
}
}
}
은 비슷, 그러나 UIGestureRecognizer
를 사용하지 마십시오.
희망이 도움이됩니다.
이 코드는 iOS 3.2 이상에서 작동합니다. – Alkimake
은 매력처럼 작동합니다! 감사합니다 Alkimake – Ibai