I have an current location annotation (blue dot) showing in mapkit. Annotation shows after taping the blue dot, how can I have the annotation showing by default?, when I start the view? whit out tapping the pin.
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views {
for(MKAnnotationView *annotationView in views) {
if(annotationView.annotation == mv.userLocation) {
self.mapView.userLocation.title= @"Current";
self.mapView.userLocation.subtitle= @"Location";
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.002;
span.longitudeDelta=0.002;
CLLocationCoordinate2D location=mv.userLocation.coordinate;
region.span=span;
region.center=location;
[mv setRegion:region animated:YES];
[mv regionThatFits:region];
}
}
}
In that case, selectAnnotation should work, wouldn't it? Just performSelector after a small time.
.... same code as before but insert this:
id annotation = annotationView.annotation;
[self performSelector:@selector(selectUserLocation:) withObject:annotation afterDelay:0.1f];
}
}
}
- (void)selectUserLocation:(id)annotation{
[self.mapView selectAnnotation:annotation animated:YES];
}
来源:https://stackoverflow.com/questions/10555583/show-current-position-annotation-by-default