Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extended mapView:viewForAnnotation Now No Blue Dot

Tags:

mapkit

I have extended MapKit's ability to draw custom annotation images with the following code:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    NSLog(@"Drawing a cloud on the map");
    MKAnnotationView *view;
    if(annotation != mapView.userLocation){
        view=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
        view.image=[UIImage imageNamed:@"placemarkCloud.png"];
        [view setCanShowCallout:YES];
        [view setRightCalloutAccessoryView:[UIButton buttonWithType:UIButtonTypeDetailDisclosure]];
    }
    else{
        view=
    }
    return view;
}

My question is what should I make view = to in order to retain the iPhone's built in blue dot. You can see that I eliminate my custom image being drawn for the dot, but I don't know how to make it show as default.

like image 773
wasabi Avatar asked Sep 10 '10 16:09

wasabi


1 Answers

Don't put anything in the else. I do the following check. I think this is derived from Apple sample code.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{

if ([annotation isKindOfClass:[MKUserLocation class]]) {
  //Don't trample the user location annotation (pulsing blue dot).
  return nil;
}

//Continue on to your regular code here.
like image 91
Nick Avatar answered Sep 24 '22 02:09

Nick