我已设置好以便我的MKMapView显示当前位置。我还为其他引脚实现了自定义引脚。然而,事实证明当前位置显示为自定义引脚,而我只是希望它是一个普通的蓝色圆圈(就像谷歌地图所有)。
我在代码中定义了以下内容:
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"];
if (pin == nil)
{
pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease];
}
else
{
pin.annotation = annotation;
}
[pin setImage:[UIImage imageNamed:@"TestPin.png"]];
pin.canShowCallout = YES;
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pin;
}
如何防止当前位置显示为引脚?
答案 0 :(得分:24)
你需要实现这个: -
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation
{
if (annotation == mapView.userLocation)
{
return nil;
}
else
{
MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"];
if (pin == nil)
{
pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease];
}
else
{
pin.annotation = annotation;
}
[pin setImage:[UIImage imageNamed:@"TestPin.png"]];
pin.canShowCallout = YES;
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pin;
}
}
答案 1 :(得分:2)
对于Swift:
if annotation is MKUserLocation {
return nil
}
答案 2 :(得分:0)
- (MKAnnotationView *)mapView:(MKMapView *)mapViewTmp viewForAnnotation:(id<MKAnnotation>)annotation
{
if(annotation == mapView.userLocation)
return nil;
else
{
MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"];
if (pin == nil)
{
pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease];
}
else
{
pin.annotation = annotation;
}
[pin setImage:[UIImage imageNamed:@"TestPin.png"]];
pin.canShowCallout = YES;
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pin;
}
}
答案 3 :(得分:0)
想要最简单的解决方案吗?只需将您的对象引脚从MKAnnotationView
更改为MKPinAnnotationView
,它就会显示您想要的内容。
答案 4 :(得分:0)
mapView.delegate=self;
MKCoordinateRegion myRegion;
CLLocationCoordinate2D center;
center.latitude=40.4000;//spean
center.longitude=-3.6833;//firstLagi;//-5.345373;
MKCoordinateSpan span;
span.latitudeDelta=My_Span;
span.longitudeDelta=My_Span;
myRegion.center=center;
myRegion.span=span;
[mapView setRegion:myRegion animated:YES];
NSMutableArray *locations=[[NSMutableArray alloc]init];
CLLocationCoordinate2D location;
Annotation *myAnn;
allList=[[AllList alloc]init];
for (int j = 0; j<[appDelegate.allListArray count]; j++)
{
cat=@"cat";
myAnn=[[Annotation alloc]init];
allList=[appDelegate.allListArray objectAtIndex:j];
location.latitude=[allList.lati doubleValue];
location.longitude=[allList.lagi doubleValue];
myAnn.coordinate=location;
myAnn.title=allList.name;
//myAnn.subtitle=allList.type;
[locations addObject:myAnn];
}
[self.mapView addAnnotations:locations];