2016-12-22 16 views
5

Tôi đang làm việc với SDK Google Maps iOS với nhiều điểm đánh dấu sẽ hiển thị cửa sổ thông tin đánh dấu trên nhấn điểm đánh dấu. Mã bên dưới hoạt động cho nhiều điểm đánh dấu và điểm đánh dấu được hiển thị trong Chế độ xem bản đồ như mong đợi. Nó cũng hiển thị cửa sổ thông tin đánh dấu trên nhấp chuột đánh dấu và thay đổi biểu tượng điểm đánh dấu khi nhấp.Làm thế nào để gõ vào ios google bản đồ đánh dấu lập trình hoặc hiển thị cửa sổ thông tin của điểm đánh dấu?

-(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;  
} 

Bây giờ tôi muốn kích hoạt lập trình nhấp vào điểm đánh dấu hoặc hiển thị cửa sổ thông tin trên điểm đánh dấu.

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

Mã trên không hoạt động đối với tôi. Nó chỉ di chuyển đến vị trí của điểm đánh dấu không hiển thị cửa sổ thông tin. Có cách nào để lập trình nhấp vào điểm đánh dấu và hiển thị cửa sổ thông tin không?

Trả lời

4

đồ Cung cấp tới điểm đánh dấu là điều cần thiết

Đối với obj c

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


[myCustomMapView setSelectedMarker:marker]; 

Đối Swift 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

Added marker.map và bây giờ làm việc của nó. –

Các vấn đề liên quan