2014-02-13 9 views
4

我正在使用Google Maps SDK for iOS應用程序。我需要自定義markerinfowindow。我在viewDidLoad中添加谷歌地圖markerInfowindow代表不會調用ios

1)@interface MapsViewController : UIViewController GMSMapViewDelegate

2)mapView_.delegate = self;

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正在添加。

回答

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; 
} 
+0

我已經添加marker.infoWindowAnchor –

1

確定它是解決我添加 mapView_.delegate =自我; 之前做標記製作感謝

13

我有同樣的問題 - markerInfoWindow即使設置委託後也不會被調用。 落得這樣做的:

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

setSelectedMarker將迫使markerInfoWindow通話。

+0

我知道這是因爲我在obj c做的,但忘記了迅速。謝謝記住這個+1 – Abi

+0

我upvoted,因爲我得到了解決方案使用你的答案。好的解決方案。 – user3182143