【问题标题】:google maps markerInfowindow delegate not calling ios谷歌地图markerInfowindow委托不调用ios
【发布时间】:2014-03-11 21:56:10
【问题描述】:

我正在使用适用于 iOS 应用的 Google Maps SDK。我需要自定义markerinfowindow。我加了

1)@interface MapsViewController : UIViewController GMSMapViewDelegate

2) mapView_.delegate = self; 在 vi​​ewdidload 和

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中没有控制。

【问题讨论】:

    标签: ios google-maps infowindow marker


    【解决方案1】:

    我遇到了同样的问题 - 即使设置了委托,markerInfoWindow 也不会被调用。 最终这样做了:

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

    setSelectedMarker 将强制调用 markerInfoWindow。

    【讨论】:

    • 我知道这一点,就像我在 obj c 中所做的一样,但很快就忘记了。感谢记住这个 +1
    • 当我使用您的答案得到解决方案时,我投了赞成票。很好的解决方案。
    【解决方案2】:

    好的,我添加了 mapView_.delegate = self; 在做标记之前谢谢

    【讨论】:

      【解决方案3】:

      要使用markerInfoWindow 方法自定义Callout,您还需要使用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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-19
        • 1970-01-01
        • 2013-07-13
        • 2017-01-18
        相关资源
        最近更新 更多