Hud*_*ddy 17 xcode location mkannotation mkannotationview ios
现在我正在使用注释填充地图视图,并显示用户的当前位置.使用viewForAnnotation方法,它会使用默认的红色引脚覆盖所有注释,但我想返回其他注释的视图,但将用户位置保留为默认的蓝色信标.有没有办法简单地执行此操作,还是必须创建新的注释视图并根据注释返回正确的注释视图?
现在我有类似的东西:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if (annotation.coordinate == locationManager.location.coordinate) {
return nil;
}else {
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Beacon"];
// Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.frame = CGRectMake(0, 0, 23, 23);
annotationView.rightCalloutAccessoryView = button;
annotationView.canShowCallout = YES;
return annotationView;
}
}
Run Code Online (Sandbox Code Playgroud)
但我无法将两者等同起因为我无法从注释参数中获取坐标属性.
有人知道任何解决方案吗?
cal*_*kus 30
查看此处的文档:
如上所述:
如果注释参数中的对象是
MKUserLocation类的实例,则 可以提供自定义视图以表示用户的位置.要使用默认系统视图显示用户的位置,请返回nil.
所以你可以添加一个条件来检查:
if([annotation isKindOfClass: [MKUserLocation class]]) {
return nil;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4963 次 |
| 最近记录: |