GMUClusterRendererDelegate 仅在渲染集群时才显示标记图标视图,而不是在该 swift 5 之前
Posted
技术标签:
【中文标题】GMUClusterRendererDelegate 仅在渲染集群时才显示标记图标视图,而不是在该 swift 5 之前【英文标题】:GMUClusterRendererDelegate show marker iconview only when cluster is rendered and not before that swift 5 【发布时间】:2020-07-26 17:23:19 【问题描述】:我正在尝试在我的谷歌地图中创建集群。当我在地图上显示集群时,我只想显示集群计数,当单击或缩放集群时,我只想显示我的自定义标记视图。 但是标记视图在集群之前已经存在,当我放大集群时,会显示默认引脚,这是我不想要的。
下面是聚类的代码
for data in self.map_data
//check if map data is on or off and show map data accordignly
let offerdata = data
let geocoder = CLGeocoder()
let strAddress = "\(offerdata.agent_street ?? "")"+" "+"\(offerdata.agent_city ?? "")"+" "+"\(offerdata.agent_zipcode ?? "")"
//MARK: GEOCODER FOR GETTING LAT LONG BASE ON ADDRESS
geocoder.geocodeAddressString(strAddress)
placemarks, error in
let placemark = placemarks?.first
let lat = Double(placemark?.location?.coordinate.latitude ?? 0.00)
let lon = Double(placemark?.location?.coordinate.longitude ?? 0.00)
print("Lat: \(String(describing: lat)), Lon: \(String(describing: lon))")
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 5)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: lat, longitude: lon)
marker.title = "\(offerdata.agent_firstname ?? "")"+" \(offerdata.agent_lastname ?? " ")"
marker.iconView?.backgroundColor = .lightGray
marker.userData = data
//amrut
// Clustering
let item = POIItem(position: CLLocationCoordinate2DMake(lat, lon), name: "marker.title" ?? "",data: data)
self.clusterManager.add(item)
//map info views
var image = UIImage()
var currency = String()
if data.currency == "AUD"
currency = "$\(data.currency ?? "")"
else if data.currency == "EUR"
currency = "€\(data.currency ?? "")"
else
currency = "£\(data.currency ?? "")"
let amount = "\(data.offer_amount ?? "")".convertTo2Decimal+" "+currency
//create custom marker accordin to condtions
// "\(agent.offer_amount ?? "")".convertTo2Decimal+" "+"\(agent.currency ?? "AUD")"
if data.auto_approval_on_off == "ON"
if (data.is_badge_display == "1")
image = UIImage(named: "blueMarker.png") ?? UIImage()//blue
else
image = UIImage(named: "orangeMarker.png") ?? UIImage()//oranfge
else if (data.is_badge_display == "1")
image = UIImage(named: "blueMarker.png") ?? UIImage()//blue
else
image = UIImage(named: "blackMarker.png") ?? UIImage()//black
let customMarker = CustomMarkerView(frame: CGRect(x: 0, y: 0, width: 100, height: 40), image:image , lblText:amount)
// marker.iconView=customMarker
marker.map = self.MapView
self.MapView.camera = camera
我在 'GMUClusterRendererDelegate willRenderMarker' 委托方法中做同样的事情,只是取消注释 marker.iconView=customMarker
谁能帮我做我需要做的事情。真的很有帮助 Image for reference Image for reference2
我想要两件事: 1-显示没有地图图标视图的初始加载集群 2- 仅显示地图图标视图,而不是集群渲染/缩放后的引脚
请有人帮助我
【问题讨论】:
【参考方案1】:我有一个类似的问题。我想出的解决方法是运行 clearMarkers 函数,然后使用 addMarkers 函数重新添加整个标记数组
我还在努力,如果我找到更好的答案,我会更新
【讨论】:
当然。我会等待解决方案。如果我发现任何问题,我会发布解决方案以上是关于GMUClusterRendererDelegate 仅在渲染集群时才显示标记图标视图,而不是在该 swift 5 之前的主要内容,如果未能解决你的问题,请参考以下文章