2011-03-16 24 views
2

我解决这个问题征求您的意见:iPhone MapView类:注释针 - 不同的颜色

我取一个XML文件在我的MapView显示引脚。在另一种方法我显示我在地图上的当前位置:

-(void)setPOIs { 

NSLog(@"insert POIs"); 

int x = 0; 

while (x < [res count]) { 

    CLLocationCoordinate2D c; 
    NSString *latitude = [[res objectAtIndex:x] objectForKey:@"latitude"]; 
    NSString *longitude = [[res objectAtIndex:x] objectForKey:@"longitude"]; 
    c.latitude = [latitude doubleValue]; 
    c.longitude = [longitude doubleValue]; 
    GPSAnnotation *annotation = [[GPSAnnotation alloc] initWithCoordinate:c]; 
    annotation.mTitle=[[res objectAtIndex:x] objectForKey:@"ordiname"]; 
    annotation.currentPoint = [NSNumber numberWithInt:[[[res objectAtIndex:x] objectForKey:@"tierarztid"] intValue]]; 
    annotation.currentRow = [res objectAtIndex:x]; 
    [mapViewOutlet addAnnotation:annotation]; 
    [annotation release]; 

    NSLog(@"latitude setPOIs: %@", latitude); 
    x++; 
} 

[self showOwn]; 

}

- (无效)showOwn {

CLLocationCoordinate2D c; 
c.latitude = location.latitude; 
c.longitude = location.longitude; 
GPSAnnotation *annotation1 = [[GPSAnnotation alloc] initWithCoordinate:c]; 
annotation1.mTitle= @"Ihr Standort"; 
[mapViewOutlet addAnnotation:annotation1]; 
[annotation1 release];  

}

我在这里展示引脚:

- (MKAnnotationView *)mapView:(MKMapView *)mapViewOutlet viewForAnnotation:(GPSAnnotation *)annotation { 

int postag = 0; 
//int row = 0; 

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; 
annView.pinColor = MKPinAnnotationColorGreen; 
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
myDetailButton.frame = CGRectMake(0, 0, 23, 23); 
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 


    // Set the image for the button 
[myDetailButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal]; 
[myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 


if ([[annotation title] isEqualToString:@"Current Location"]) { 
    postag = 99999; 
} else { 
    postag = [annotation.currentPoint intValue]; 

} 



myDetailButton.tag = postag; 

// Set the button as the callout view 
annView.rightCalloutAccessoryView = myDetailButton; 

annView.animatesDrop=NO; 
annView.canShowCallout = YES; 
annView.calloutOffset = CGPointMake(-5, 5); 


return annView; 

[annView release]; 

}

我能做些什么来显示我当前位置的自定义图像 - 和/或不显示泄露按钮?

+0

重复? http://stackoverflow.com/questions/5329575/setting-up-image-in-mkannotationpinview/5329771 – GendoIkari 2011-03-16 22:31:32

回答

0

而不是使用MKPinAnnotationView使用MKAnnotationViewMKPinAnnotationViewMKAnnotationView的一个子类。 MKPinAnnotationView将只显示引脚。 MKAnnotationView有一个图像属性,您可以设置显示不同的图像而不是针。

显示披露按钮的代码行是您的rightCalloutAccessoryView指令。把它拿出来,标注中的详细信息将会消失。

0
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
if ([annotation isKindOfClass:[ParkingSpot class]]) 
    { 
     static NSString* AnnotationIdentifier = @"ParkAnnotationIdentifier"; 
     MKAnnotationView* annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:ParkAnnotationIdentifier]; 
     if (!annotationView) 
     { 
      MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease]; 
      annotationView.draggable = NO; 
      UIImage *annotationImage = ...your image here 
      annotationView.image = annotationImage; 
     } 
    return annotationView; 
    } 
} 
1

感谢您的意见!我简单地适应一个if ... else语句

- (MKAnnotationView *)mapView:(MKMapView *)mapViewOutlet viewForAnnotation:(GPSAnnotation *)annotation { 

int postag = 0; 
//int row = 0; 

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; 
annView.pinColor = MKPinAnnotationColorGreen; 
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
myDetailButton.frame = CGRectMake(0, 0, 23, 23); 
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 


if ([[annotation title] isEqualToString:@"Ihr Standort"]) { 
    postag = 99999; 
    UIImage *annotationImage = [UIImage imageNamed:@"07-map-marker.png"]; 
    annView.image = annotationImage; 
} else { 
    postag = [annotation.currentPoint intValue]; 
    [myDetailButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal]; 
    [myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 

} 



myDetailButton.tag = postag; 

// Set the button as the callout view 
annView.rightCalloutAccessoryView = myDetailButton; 

annView.animatesDrop=NO; 
annView.canShowCallout = YES; 
annView.calloutOffset = CGPointMake(-5, 5); 


return annView; 

[annView release]; 

}

BR解决,

斯特凡