【问题标题】:User location annotation misplaced when not default非默认时用户位置注释放错了位置
【发布时间】:2011-08-17 18:32:14
【问题描述】:

我在 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];
        }
    }
}

有谁知道为什么我的注释在使用红色图钉而不是默认注释视图时不再正确放置?

【问题讨论】:

    标签: iphone sdk annotations location android-mapview


    【解决方案1】:

    设置[pin setAnimatesDrop:NO] 而不是YES 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多