2017-04-30 98 views
0

我想添加一个自定义信息窗口,以便在有人点击某个图钉时在Google地图中弹出。我已经通过不通过任何数据隐藏当前的信息窗口,并知道该功能将自定义信息窗口添加到Google地图

func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool { 

    return true 
} 

手柄时的针被窃听发生了什么。目前,我有这个自定义的UIView和我的MapViewController属性和相应的网点添加到视图控制器代码: enter image description here

我将如何实现这个UIView的弹出每当我点击一个针?

+0

试试这个https://stackoverflow.com/questions/29462187/creating-custom-info-window-in-swift-with-the-google-maps-ios-sdk –

回答

1

你必须使用GMSMapViewDelegate使用markerInfoWindow你的课。

let mapview = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 

mapview.delegate = self 


func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? { 
    // Get a reference for the custom overlay 
    let index:Int! = Int(marker.accessibilityLabel!) 
    let customInfoWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self, options: nil)?[0] as! CustomInfoWindow 
    customInfoWindow.Timings.text = States[index].time 
    customInfoWindow.Title.text = States[index].name 
    customInfoWindow.Direction_Button.tag = index 
    customInfoWindow.Direction_Button.addTarget(self, action: #selector(GetDirectionsAction(sender:)), for: .touchUpInside) 

    return customInfoWindow 
} 
2

您应该创建注释的自定义视图,然后返回自定义视图以下方法:

func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? { 
//Create and load your custom view here and then return the view 
} 
+0

我已经试过了,但我的屏幕上没有显示任何内容。 – ch1maera

相关问题