1
我在MKMapView显示用户位置。我不想要默认的蓝色圆圈,而是红色的针脚。用户位置注释错误,当不是默认的
因此,我实现了mapView:viewForAnnotation:并且始终返回一个红色的针,因为用户的位置是我将在地图视图中显示的唯一针。
当使用默认的蓝色圆圈时,位置非常精确,但当切换到红色针时,它会关闭很多。就好像红色针脚正好掉落,然后向上移动,因此不再显示我的当前位置。
这是我的代码:
- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
NSLog(@"MapView: Annotation.");
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
[pin setPinColor:MKPinAnnotationColorRed];
[pin setAnimatesDrop:YES];
[pin setCanShowCallout:NO];
return pin;
}
我使用的MapView:didAddAnnotationViews:将地图视图我目前的位置。
- (void)mapView:(MKMapView *)_mapView didAddAnnotationViews:(NSArray *)views
{
for(MKAnnotationView *annotationView in views)
{
if(annotationView.annotation == _mapView.userLocation)
{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.20;
span.longitudeDelta = 0.20;
CLLocationCoordinate2D location = [[_mapView userLocation] coordinate];
region.span = span;
region.center = location;
[_mapView setRegion:region animated:YES];
[_mapView regionThatFits:region];
}
}
}
有没有人知道为什么我的注释不再使用红色的引脚而不是默认的注释视图?