更改地图类型而不会丢失我的自定义Pin

时间:2012-11-07 17:55:37

标签: objective-c xcode mkmapview mkannotationview

我有一个带有许多图钉的地图视图!一切都运作良好,但如果我改变maptype ...正常..卫星或ibrid ..我失去了我的形象,我的销成为标准红色别针!我可以在不改变任何内容的情况下更改maptype吗?

我使用此代码分配不同的图像:

- (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;

}

1 个答案:

答案 0 :(得分: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;