2012-11-07 53 views
1

我有許多具有不同圖像的圖釘的地圖視圖!一切正常,但如果我改變maptype ...正常..衛星或ibrid ..我失去了我的形象和我的針腳成爲標準的紅色針腳!我可以在不更改任何內容的情況下更改maptype嗎?更改地圖類型而不會丟失我定製的Pin

我使用此代碼來分配不同的圖像:

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

} 
+0

重複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,和多一些。 – Anna

回答

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; 
+2

一些評論會幫助這個答案 – dove

相關問題