1

I've a mapview with many pins that have different images! Everything work good but if I change the maptype... normal.. satellite or ibrid.. i lose my image and my pin became the standars red pins! Can I change the maptype without change anything?

I use this code to assign the different images:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id  <MKAnnotation>)annotation
{
annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];

if([annotation.title compare:@"Biggest"]==0){imageView = [UIImage imageNamed:@"pin.png"];annView.image=imageView;}
if([annotation.title compare:@"Campo sportivo"]==0){imageView = [UIImage imageNamed:@"mondo.png"];annView.image=imageView;}
if([annotation.title compare:@"BlackSheep ADV"]==0){imageView = [UIImage    imageNamed:@"an.png"];annView.image=imageView;}


annView.pinColor = MKPinAnnotationColorRed;
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

[advertButton addTarget:self action:@selector(button:)       forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = advertButton;

annView.animatesDrop = TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(0, 5);

if ([annotation isKindOfClass:[MKUserLocation class]]){
                                                    return nil;
                                                  }
return annView;

}
user1639377
  • 117
  • 1
  • 7
  • Duplicate of http://stackoverflow.com/questions/5136545/change-mkmaptype-in-mkmapview-and-keep-custom-pinimage-for-annotations, http://stackoverflow.com/questions/3577691/iphone-core-location-custom-pin-image-disappears-when-map-type-changes, http://stackoverflow.com/questions/5151378/ios-mapkit-changing-mapview-maptype-causes-annotation-image-to-change-to-pin, http://stackoverflow.com/questions/6430093/pin-images-change-after-map-type-change, http://stackoverflow.com/questions/2087738/iphone-mapkit-annotation-images-get-reset-back-to-pins, and a few more. –  Nov 07 '12 at 18:04

1 Answers1

3
    - (void) changeMapType: (id)sender
    {
        if (mapView.mapType == MKMapTypeStandard)
            mapView.mapType = MKMapTypeSatellite;
        else
            mapView.mapType = MKMapTypeStandard;
    } 

This method works as according to google maps have two types
1) standard
2) satellite

So by default if you use google maps, it is in the form of MKMapTypeStandard you can change if you want by             mapView.mapType = MKMapTypeSatellite;
Deep Batra
  • 112
  • 5