google maps markerInfowindow委托不调用ios

时间:2014-02-13 06:51:28

标签: ios google-maps infowindow marker

我正在使用Google Maps SDK for iOS应用。我需要自定义markerinfowindow。我添加

1)@interface MapsViewController : UIViewController GMSMapViewDelegate

2){},mapView_.delegate = self;在viewdidload和

3)

 - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
            UIView *InfoWindow = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 200)];
            UILabel *nameLabel = [[UILabel alloc]init];
             nameLabel.text = @"hi";
             [InfoWindow addSubview:nameLabel];

    return InfoWindow;
}

但是控制没有在markerInfoWindow中出现。

3 个答案:

答案 0 :(得分:14)

我遇到了同样的问题 - 即使在设置委托后,也不会调用markerInfoWindow。 结束这样做:

- (BOOL)mapView:(GMSMapView*)mapView didTapMarker:(GMSMarker*)marker
{
  [mapView setSelectedMarker:marker];
  return YES;
}

setSelectedMarker将强制对markerInfoWindow进行调用。

答案 1 :(得分:2)

要使用markerInfoWindow方法进行自定义标注,您还需要使用infoWindowAnchor属性设置其锚点。

创建标记时设置锚点:

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = MARKER_POSITION;
marker.infoWindowAnchor = CGPointMake(0.44f, 0.45f);
marker.icon = [UIImage imageNamed:@"CustomMarkerImageName"];

然后创建委托方法。

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  InfoWindow *view =  [[[NSBundle mainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];
  view.name.text = @"Place Name";
  view.description.text = @"Place description";
  view.phone.text = @"123 456 789";
  view.placeImage.image = [UIImage imageNamed:@"customPlaceImage"];
  view.placeImage.transform = CGAffineTransformMakeRotation(-.08);
  return view;
}

答案 2 :(得分:2)

好的,我已经解决了 mapView_.delegate = self; 在做标记之前谢谢