我有一张包含 3 类兴趣点的地图。目前我已经让它们显示,但是它们都是相同的颜色。我怎样才能让他们根据他们所在的类别显示颜色?
我四处搜索,找不到任何我能理解的适用于我的代码的东西。
这是我当前用于注释引脚的代码:
-(void)pins:(NSString *)name lat:(NSString *)lat lon:(NSString *)lon poiID:(NSString *)poiID
{
//cast string to float
CGFloat Lat = (CGFloat)[lat floatValue];
CGFloat Lon = (CGFloat)[lon floatValue];
//Set coordinates of pin
CLLocationCoordinate2D coordinate;
coordinate.latitude = Lat;
coordinate.longitude = Lon;
//Create Pin
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
//set details
[annotation setCoordinate:coordinate];
[annotation setTitle:name];
[annotation setAccessibilityLabel:poiID]; //set the label eq to the id so we know which poi page to go to
// Add pin to map
[self.showMapView addAnnotation:annotation];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
//create annotation
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.animatesDrop = FALSE;
pinView.canShowCallout = YES;
//details button
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
} else {
pinView.annotation = annotation;
}
return pinView;
}
这是我的代码的其余部分,以防需要。
谢谢你的帮助。