3

I am not able to see the Blue current location dot when I use custom annotations

- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id<MKAnnotation> ) annotation {    MKAnnotationView *customAnnotationView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];    UIImage *pinImage = [UIImage imageNamed:@"ann.png"];    [customAnnotationView setImage:pinImage];    customAnnotationView.canShowCallout = YES;                                                                                                 //UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ann.png"]]; //customAnnotationView.leftCalloutAccessoryView = leftIconView; UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; customAnnotationView.rightCalloutAccessoryView = rightButton;    return customAnnotationView; } 
1
  • You're not reusing your annotations, which becomes a significant memory waste if you have many of them and/or the user keeps panning around the map. Commented Jan 20, 2011 at 11:25

3 Answers 3

8
if (annotation == map.userLocation) { return nil; } 

Add this.:d

Sign up to request clarification or add additional context in comments.

Comments

2

I got the answer now. Just need to add the following lines to the above code at the end just before return customAnnotationView;

if (annotation == mapView.userLocation) {
NSLog(@"nil"); return nil; }

thanks :)

1 Comment

@user582835 If you're going to do it that way, don't put it down at the bottom, put it right at the top. You don't want to do all of that processing on an annotation that can't even use it. In addition you definitely don't need to log "nil".
1

The visibility of the current user location "blue dot" is unrelated to custom annotations. To make the user's current location show, you need to set the showsUserLocation property of your MKMapView to YES. For example:

yourMapView.showsUserLocation = YES; 

or:

[yourMapView showsUserLocation] = YES; 

Understand that there is a quirk in the way MapKit displays the current user location: in the simulator the UserLocation will always be Apple's headquarters in Cupertino, CA, USA. It will work fine on the device, however.


Edited to add:

As Terente points out, you do have to be careful not to "eat" the user's location annotation, and so must test to see if the annotation you're processing is the user's location. I wrap the logic with:

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

Where MapLocation is my annotation class.

2 Comments

I have done it. But I dont get the blue dot. I did as I stated in the posts below I am getting it now. Thanks
+1 For mentioning that the simulator uses Cupertino as UserLocation... :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.