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.?
+2
A:
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;
}
Cannonade
2010-03-09 01:26:03
thanks i solved the issue
Anmol Bajpai
2010-04-28 23:29:30
@anmol-bajpai glad to hear it.
Cannonade
2010-04-29 01:42:03
If my answer was useful, feel free to accept/upvote it ;)
Cannonade
2010-04-29 01:50:22
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
blackkettle
2010-06-10 05:19:43
@blackkettle Glad it was useful and thanks for the link :)
Cannonade
2010-06-10 05:30:53