我有一张地图,其中有三种类别的兴趣点。目前我已经让它们显示出来了,但它们都是相同的颜色。我该如何让它们显示不同的颜色,根据它们所属的类别呢?
我已经搜索了一下,但没有找到可以应用到我的代码中的东西。
这是我当前用于注释标记的代码:
我已经搜索了一下,但没有找到可以应用到我的代码中的东西。
这是我当前用于注释标记的代码:
-(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;
}
如果需要,这里是我代码的其余部分。
感谢任何帮助。