2016-12-22 64 views
5

我正在使用帶有多個標記的Google Maps iOS SDK,它將在標記點擊上顯示標記信息窗口。下面的代碼適用於預期的地圖視圖中顯示的多個標記和標記。它還在標記點擊時顯示標記信息窗口,並在點擊時更改標記圖標。如何以編程方式點擊ios谷歌地圖標記或顯示標記的信息窗口?

-(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)imarker 
{ 
    UIView *infowindow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 90, 45)]; 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 90, 45)]; 
    [label setFont:[UIFont fontWithName:@"TrebuchetMS-Bold" size:22]]; 
    infowindow.layer.cornerRadius = 5; 
    infowindow.layer.borderWidth = 2; 
    label.textAlignment = NSTextAlignmentCenter; 
    label.text = @"Test"; 
    label.textColor=[UIColor greenColor]; 
    infowindow.backgroundColor=[UIColor whiteColor]; 
    [infowindow addSubview:label]; 
    return infowindow;  
} 

現在我想觸發編程方式點擊標記上的標記或顯示信息窗口。

marker = [GMSMarker markerWithPosition:position]; 
marker.title = @"Name"; 
marker.snippet = @"Test";   
[self mapView:_mapView didTapMarker:marker]; 
[_mapView setSelectedMarker:marker]; 

上面的代碼不適合我。它只是移動到標記的位置不顯示信息窗口。有什麼方法可以通過編程方式點擊標記並顯示信息窗口?

回答

4

提供地圖標記是必不可少的

有關的OBJÇ

GMSMarker *myMarkerAutomaticSnippet = [[GMSMarker alloc] init]; 
marker.position = <Your cordinates>; 
marker.title = @"my Title"; 
marker.snippet = @"my Snippet"; 
marker.map = myCustomMapView; 


[myCustomMapView setSelectedMarker:marker]; 

對於雨燕3.0

let myMarker = GMSMarker() 
    myMarker.position = CLLocationCoordinate2DMake(80.0, 80.0) 
    myMarker.title = "marker title" 
    myMarker.snippet = "marker snippet" 
    myMarker.map = customMap // Here custom map is your GMSMapView 


    customMap.customMapView.selectedMarker = myMarker // This line is important which opens the snippet 
+1

新增marker.map,現在它的工作。 –

相關問題