【发布时间】:2019-05-31 22:39:39
【问题描述】:
我有一个使用 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
}
这不起作用仍然欢迎任何帮助
【问题讨论】:
-
您希望自定义视图如何出现/呈现在屏幕上?
-
@bsod 就像一个工具提示。具有该坐标中包含的详细信息的 UIView
-
您不需要自定义视图,Google 地图有一个内置的标记信息窗口(工具提示):developers.google.com/maps/documentation/ios-sdk/…
-
我有一些标签和图像视图要添加到视图中
标签: swift google-maps