Mapkit problem in determining the current position of annotation

I am using a map set in my application and I am using this first time, so please tell me how to find the current position of the annotation.

+3
source share
1 answer

To add annotations to MapKit, you need to implement an annotation delegate that implements the MKAnnotation protocol. When you add an annotation to the map, you instantiate the Annotation Delegate object and then add it to MKMapView. MKAnnotation includes a position property that you can request to locate the annotation:

@interface AnnotationDelegate : NSObject <MKAnnotation> {
    CLLocationCoordinate2D coordinate;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@end

To add your annotation to the map:

AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] init] autorelease];
[mapView addAnnotation:annotationDelegate];

, calloutAccessoryControlTapped , MKAnnotationView.nnation position:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    AnnotationDelegate * delegate = (AnnotationDelegate*)view.annotation;
    // do stuff with delegate.position;
}
+2

Source: https://habr.com/ru/post/1736023/


All Articles