我有一个使用Googlemaps的应用程序,我能够为所有所需的坐标创建标记,但我现在面临的问题是,当用户点击一个标记以显示与该标记相关的信息时,我想显示一个自定义的UIView。
func showFeaturedProperties(properties: [FeaturedProperties]) {
self.properties = properties
properties.forEach { (props) in
var lat = Double(props.latitude!) as! Double
var lng = Double(props.longitude!) as! Double
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: lat,
longitude: lng)
marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
marker.isFlat = true
marker.map = mapView
if props.typeId == 1 {
marker.icon = #imageLiteral(resourceName: "_map_rent_icon")
} else {
marker.icon = #imageLiteral(resourceName: "_map_buy_icon")
}
marker.setIconSize(scaledToSize: .init(width: 25, height: 25))
marker.iconView?.contentMode = .scaleAspectFit
self.markers.append(marker)
}
}上面的代码显示了地图上的标记,单击标记时如何显示详细信息?
到目前为止,我已经扩展了GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView? {
if let index = markers.index(of: marker) {
let tappedState = properties[index]
log(tappedState.id)
}
let infoView = BaseCardView()
return infoView
}这是行不通的,但欢迎任何帮助。
发布于 2019-06-01 05:02:15
https://stackoverflow.com/questions/56402421
复制相似问题