我的地图上有针脚,当前位置显示为蓝点。我补充说:
- (MKAnnotationView *)mapView:(MKMapView *)amapView viewForAnnotation:(id<MKAnnotation>)annotation{
NSString *identifier =@"mypin";
MKPinAnnotationView *pin = (MKPinAnnotationView *) [amapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(pin ==nil){
pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
}else{
pin.annotation = annotation;
}
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
pin.rightCalloutAccessoryView = myDetailButton;
pin.enabled = YES;
pin.animatesDrop = TRUE;
pin.canShowCallout = YES;
return pin;
}
但是现在当前的位置是针脚而不是蓝点。如何停止当前位置的注释成为引脚并将其保持为蓝点。
请帮忙吗?
答案 0 :(得分:1)
“蓝点”是一个特殊的注释,MKUserLocation
。因此,在您的viewForAnnotation
中,只需在开头添加以下两行,告诉iOS使用标准“蓝点”作为用户位置注释:
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
通过返回nil
,您将告诉iOS使用默认的“蓝点”注释作为用户位置。
有关此实例的示例,请参阅位置感知编程指南的Creating Annotation Views from Your Delegate Object部分中的代码示例。
答案 1 :(得分:0)
简单:
- (MKAnnotationView *)mapView :(MKMapView *)maapView viewForAnnotation:(id <MKAnnotation>) annotation{
@autoreleasepool {
if (annotation == maapView.userLocation)
{
// This code will execute when the current location is called.
return nil;
}
else
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorPurple;
annView.animatesDrop=YES;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annView.rightCalloutAccessoryView = rightButton;
return annView;
}
}
}
答案 2 :(得分:0)
清洁和快速(3)方式
if annotation is MKUserLocation {
return nil
}