问题:气泡上显示乘客的头像,怎样获取到每个大头针对应哪个头像
解决:可以继承MAPointAnnotation, 类似下面代码
@interface YourPointAnnotation : MAPointAnnotation
@property UIImageView* yourImageView;
@end
调用addAnnotation:时添加的类型改为YourPointAnnotation
上代码:
pragma mark - 打点(附近的乘客和司机)
-
(void)addPersonAnnotation{
NSArray *personArr = self.personsLocationDict[@"persons"];
NSInteger count = personArr.count;
for (NSInteger i=0; i<count; i++) {
NSDictionary *personDict = personArr[i];
NSArray *locationArr = personDict[@"gaodeLocation"];
QCXPointAnnotation *pointAnnotation = [[QCXPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake([locationArr[1] floatValue], [locationArr[0] floatValue]);
pointAnnotation.title = personDict[@"name"];
pointAnnotation.subtitle = personDict[@"nickName"];UIImageView *headerImgView = [[UIImageView alloc] init]; headerImgView.frame =CGRectMake(0, 0, 50, 50); [headerImgView sd_setImageWithURL:personDict[@"picture"] placeholderImage:[UIImage imageNamed:@"car"]]; pointAnnotation.headImageView = headerImgView; [self.annotationsArr addObject:pointAnnotation];
}
[self.mapView addAnnotations:self.annotationsArr];
[self.mapView showAnnotations:self.annotationsArr animated:YES];
}
代理方法:
-
(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
{if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *reuseIndetifier = @"annotationReuseIndetifier";
MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
if (annotationView == nil)
{
annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
}annotationView.canShowCallout = YES; annotationView.draggable = YES; annotationView.image = [UIImage imageNamed:@"car"]; QCXPointAnnotation *qcxAnn = annotation; annotationView.leftCalloutAccessoryView = qcxAnn.headImageView; return annotationView;
}
return nil;
}
结束
网友评论