如何点击精确定位时如何在RMMapview中显示自定义annotationView?

时间:2012-05-16 06:17:56

标签: iphone ipad

我已经实现了tapOnMarker选择器,并创建了自定义的annotationView。并且它显示了annotationView,但是当我点击精确定位时,则annotationView抽象精确计数小于当前精确点的精确点,并且精确定位数显示在annotationView上,这是我的实现代码。

- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
    frame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redbox.png"]];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame =CGRectMake(0, 0,0, 0);
    [button setBackgroundImage:[UIImage imageNamed:@"pinMarker.png"] forState:UIControlStateNormal];
    button.enabled = YES;
    button.userInteractionEnabled = YES;
    [button addTarget:self action:@selector(markerLabelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [marker setLabel:frame];
}

- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map { frame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redbox.png"]]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame =CGRectMake(0, 0,0, 0); [button setBackgroundImage:[UIImage imageNamed:@"pinMarker.png"] forState:UIControlStateNormal]; button.enabled = YES; button.userInteractionEnabled = YES; [button addTarget:self action:@selector(markerLabelButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; [marker setLabel:frame]; }

1 个答案:

答案 0 :(得分:1)

加载标记时,请执行以下步骤:

RMMarker *marker = [[RMMarker alloc]initWithUIImage:img anchorPoint:CGPointMake(0.5, 1.0)];
[marker setText:@"hello"  forMarker: marker];
[marker hideLabel];

- (void) setText: (NSString*) text forMarker: (RMMarker*) marker
{
  CGSize textSize = [text sizeWithFont: [RMMarker defaultFont]]; 
  CGPoint position = CGPointMake(  -(textSize.width/2 - marker.bounds.size.width/2), 0 );
  [marker changeLabelUsingText: text position: position font: [UIFont systemFontOfSize: 15.0]foregroundColor: [UIColor whiteColor] backgroundColor: [UIColor blackColor]];  
}

无论何时单击标记,都会调用这些方法并显示标记:

- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
  NSArray* markers = [self.markerManager markers];
  for(RMMarker* m in markers) {
    if ([m class] == [RMMarker class])
      [m hideLabel];
  }
  [marker showLabel];   
}