ShowUserLocation returns pin instead of blue dot in iPhone simulator

This is my method -mapView:viewForAnnotation , which drops contacts when creating annotations. But when I set mapView.showsUserLocation = YES; in -viewDidLoad , I get a pin that fell on an infinite loop (expected in the simulator), and not the usual blue dot.

 - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ MKAnnotationView *anno = nil; //create a pin annotation view MKPinAnnotationView *pin=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"]autorelease]; [pin setPinColor:MKPinAnnotationColorRed]; pin.animatesDrop=YES; pin.canShowCallout = YES; pin.calloutOffset = CGPointMake(-5, 5); anno = pin; return anno; } 

How can I make him reset the pins and show the blue dot?

thanks

+4
source share
3 answers

Really easy to fix, although not sure if this is the right way to do it ...

 if (annotation == mapView.userLocation){ return nil; //default to blue dot } 
+24
source

As in the other answer, here's something close:

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { NSString *annotationType = [NSString stringWithCString:object_getClassName(annotation)]; if ([annotationType compare:@"NSKVONotifying_MKUserLocation"] == 0) return nil; ... } 

Of course, use something similar at your own peril and risk. It may stop working tomorrow if Apple decides to change that name.

0
source

Often you use your own annotation class to search for annotation related information. In this case, to process only your own annotations, use something like

 if ([annotation isKindOfClass:[MapLocation class]]) {} 
0
source

All Articles