【问题标题】:how to show default user location and a customized annonation view in map kit?如何在地图套件中显示默认用户位置和自定义注释视图?
【发布时间】:2010-12-09 01:43:11
【问题描述】:

我正在使用地图套件并显示自定义注释视图。一个是 carImage,另一个是 userImage(作为用户的当前位置)。现在我想显示地图套件提供的当​​前用户位置默认值。但无法显示它。如何在地图套件中显示蓝色圆圈+我的汽车?

【问题讨论】:

    标签: objective-c xcode iphone-sdk-3.0 mapkit mkpinannotationview


    【解决方案1】:

    要显示用户位置,请在地图视图对象上将以下属性设置为 true

    mapView.showsUserLocation = YES;
    

    要显示自定义注释,请在地图视图注释上设置图像属性

     - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
    {
    // check for nil annotation, dequeue / reuse annotation
    // to avoid over riding the user location default image ( blue dot )
    
    if ( mapView.UserLocation == annotation ) {
    
    return nil; // display default image
    
    }
    
    MKAnnotationView* pin = (MKAnnotationView*)
    [mapView dequeueReusableAnnotationViewWithIdentifier: PIN_RECYCLE_ID];
    
    if ( pin == nil ) {
    
    pin = [(MKAnnotationView*) [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: PIN_RECYCLE_ID] autorelease] ;
    
    pin.canShowCallout = YES;
    
    }
    else {
    
    [pin setAnnotation: annotation];
    }
    
    pin.image = [UIImage imageNamed:@"car-image.png"];
    
    return pin;
    }
    

    【讨论】:

    • 我没有看到“注释”对象具有 Image 属性!我错过了什么吗?如果我创建 MKPinAnnotationView 对象并将图像分配给它,图像不会出现!
    • 你是对的,图像是 MKAnnotationView 的成员而不是 MKAnnotation。我已经相应地更新了代码示例,为评论 +1。
    • 也感谢我 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多