MKAnnotationView for userLocation pin iPhone
Posted
by
Mauricio Galindo
on Stack Overflow
See other posts from Stack Overflow
or by Mauricio Galindo
Published on 2010-12-31T04:52:59Z
Indexed on
2010/12/31
4:53 UTC
Read the original article
Hit count: 315
I have an application that uses MKMapView and at some point in the app I need to remove all the current pins in the map using
[mapView removeAnnotations:mapView.annotations]
And then I want to show again the current user location
mapView.showUserLocation = YES
But I can only make it reappear as a regular pin, because the userLocation view class its not public so I cant return views of that type. Here is my code
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
MKPinAnnotationView* annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"currentloc"];
if (!annView) {
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; annView.pinColor = MKPinAnnotationColorRed; annView.animatesDrop=TRUE; annView.canShowCallout = YES; annView.calloutOffset = CGPointMake(-5, 5); if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable = YES; return annView;
} else { if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable = YES; annView.annotation = annotation; return annView; }
Also I have found through reflection that
MKUserLocationView
is the class that is used to display the current location, but because its not public its not safe to use and my app keeps crashing and Im sure theres a easier way.
Is it possible to do what I want, or should I just never remove the user location annotation of the mapView?
Thanks in advance
© Stack Overflow or respective owner