사용자가지도를 터치 할 때 주석 추가에 몇 가지 문제가 있습니다.MapKit 및 UIGestureRecognizer를 사용하여 터치시 주석 핀 추가
나는 사용자의 터치를 감지하기 위해 UIGestureRecognizer
을 사용하고 있습니다. 길게 누르면이 감지되면
는,이 함수를 호출하고 있습니다 :
- (void)handleLongPressGesture:(UIGestureRecognizer*)gestureRecognizer{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) return;
NSLog(@"long press");
CGPoint touchPoint = [gestureRecognizer locationInView:mapView];
CLLocationCoordinate2D touchMapCoordinate =
[mapView convertPoint:touchPoint toCoordinateFromView:mapView];
RdvAnnotation *rdvAnnotation = [[RdvAnnotation alloc] init];
[rdvAnnotation initWithCoordinate:touchMapCoordinate];
[mapView removeAnnotations:mapView.annotations];
[mapView addAnnotation:rdvAnnotation];
[rdvAnnotation release]; }
I 캔은 콘솔에서 NSLog를 확인하고 rdvAnnotation
는 좌표 좋은 초기화됩니다.
지도에서 내 특수 효과를 볼 수없는 이유를 알 수 없습니다.
여기 내 - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
방법입니다 :
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[RdvAnnotation class]])
{
static NSString* RdvAnnotationIdentifier = @"rdvAnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[mapView dequeueReusableAnnotationViewWithIdentifier:RdvAnnotationIdentifier];
if (!pinView)
{
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:RdvAnnotationIdentifier] autorelease];
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
return customPinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;}
내 viewDidLoad
방법 : 당신은 두 번 초기화 호출하고
RdvAnnotation *rdvAnnotation = [[RdvAnnotation alloc] init];
[rdvAnnotation initWithCoordinate:touchMapCoordinate];
: 난 그냥 이상한 것 같다 뭔가를 발견
- (void)viewDidLoad {
[super viewDidLoad];
mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
[mapView setShowsUserLocation:TRUE];
[mapView setMapType:MKMapTypeStandard];
[mapView setDelegate:self];
CLLocationManager *locationManager=[[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager startUpdatingLocation];
self.navigationItem.title = @"Rendez-vous" ;
}
'- (MKAnnotationView *) mapView : (MKMapView *) mapView viewForAnnotation : (id) annotation' MapView delegate을 구현 했습니까? 실제보기가 생성됩니다. –
adig
예, 질문을 업데이트했습니다. 뭐가 잘못 보이니? – Serviet
괜찮을 것 같습니다. 그것은 좌표 변환에 제스처 위치와 관련이있을 수 있습니까? 좌표가지도 뷰의 표시 영역에 있는지 확인할 수 있습니까? – adig