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.?
Asked
Active
Viewed 1,218 times
3
-
Are you still having a problem finding the position on the annotation? If so, please update the question with details. – RedBlueThing Mar 13 '10 at 13:08
1 Answers
2
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;
}

RedBlueThing
- 42,006
- 17
- 96
- 122
-
-
thanks this really helped me out. i pointed to this and one other of your posts in a question of my own, http://stackoverflow.com/questions/3011536/iphone-mapkit-problems-viewforannotation-inconsistently-setting-pincolor – si28719e Jun 10 '10 at 05:19