Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapkit issue in finding annotation current position

Tags:

iphone

mapkit

I am implementing map kit in my app and i am using this first time so please tell me how to find the current position of the annotation.?

like image 395
Anmol Bajpai Avatar asked Nov 19 '25 00:11

Anmol Bajpai


1 Answers

To add annotations to MapKit you need to implement an Annotation Delegate which implements the MKAnnotation protocol. When you add the annotation to the map you create an instance of you Annotation Delegate object and then add it to the MKMapView. MKAnnotation includes a position property which you can query to determine the location of 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];

Then when you get a calloutAccessoryControlTapped callback, you can cast the MKAnnotationView.annotation to your Annotation Delegate class and then query the position property:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    AnnotationDelegate * delegate = (AnnotationDelegate*)view.annotation;
    // do stuff with delegate.position;
}
like image 108
RedBlueThing Avatar answered Nov 20 '25 13:11

RedBlueThing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!