【问题标题】:how can i place two color pins ? 1 in red and 1 in green?我怎样才能放置两个颜色的别针? 1个红色和1个绿色?
【发布时间】:2011-04-27 09:33:17
【问题描述】:

我正在使用这个示例应用来制作路线

http://blog.kadirpekel.com/2010/05/30/drawing_routes_onto_mkmapview_using_unofficial_google_maps_directions_api/

它会调用路由api并解析结果。

然后在地图上方添加一个新图层,其中包含 A 和 B 之间的路线。

我的问题是如何放置两个颜色的别针?现在它显示 2 个红色引脚。但我需要 1 个红色和 1 个绿色。

我正在尝试与该代表合作,但它对我没有帮助

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

【问题讨论】:

    标签: iphone google-maps mapkit mkmapview mkannotation


    【解决方案1】:
    - (MKAnnotationView *)mapView:(MKMapView *)mapView 
                viewForAnnotation:(id <MKAnnotation>)annotation {
    
        if(annotation == yourFirstAnnotation)
    {
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:yourFirstAnnotation reuseIdentifier:[annotation title]];
                annView.pinColor = MKPinAnnotationColorRed;
                annView.animatesDrop=NO;
                annView.canShowCallout = YES;
                return [annView autorelease];
    }
    else
    if(annotation == yourSecondAnnotation)
    {
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:yourSecondAnnotation reuseIdentifier:[annotation title]];
                annView.pinColor = MKPinAnnotationColorGreen;
                annView.animatesDrop=NO;
                annView.canShowCallout = YES;
                return [annView autorelease];
    }
    }
    

    我认为如果它不起作用,请使用 isEqual: 而不是 ==

    【讨论】:

      猜你喜欢
      • 2021-11-07
      • 2014-05-14
      • 2021-04-13
      • 2018-04-29
      • 2016-01-01
      • 2020-10-29
      • 2014-04-27
      • 1970-01-01
      • 2017-05-28
      相关资源
      最近更新 更多