如何在iOS版GoogleMaps中使用自定义标记进行标记聚类? [英] How to make marker clustering with custom markers in GoogleMaps for iOS?

查看:136
本文介绍了如何在iOS版GoogleMaps中使用自定义标记进行标记聚类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS开发的初学者. 我在应用程序上添加了GoogleMaps,可以对GoogleMaps的默认标记进行聚类,但是当我根据计算机上的图像自定义标记时,这些自定义标记就无法聚类. 有人可以帮助我在Swift 3中做到这一点吗?

I'm a beginner in iOS development. I added a GoogleMaps on my app, I can cluster the default markers of GoogleMaps but when I custom markers by an image from my computer, the custom markers can't cluster. Someone can help me to do it in Swift 3?

我向您展示了我的代码的一部分:

I show you a part of my code :

override func viewDidLoad() {

mapView = GMSMapView(frame: view.frame)
mapView.camera = GMSCameraPosition.camera(withLatitude: 48.898902, longitude: 2.282664, zoom: 12.0)
mapView.mapType = .normal
mapView.delegate = self
view.addSubview(mapView)

if isClustering {
    var iconGenerator: GMUDefaultClusterIconGenerator!
    if isCustom { // Here's my image if the event are clustered
        var images: [UIImage] = [UIImage(named: "m1.png")!, UIImage(named: "m2.png")!, UIImage(named: "m3.png")!, UIImage(named: "m4.png")!, UIImage(named: "m5.png")!]
        iconGenerator = GMUDefaultClusterIconGenerator(buckets: [10, 20, 50, 100, 200], backgroundImages: images)
    } else {
        iconGenerator = GMUDefaultClusterIconGenerator()
    }

    let algorithm = GMUNonHierarchicalDistanceBasedAlgorithm()
    let renderer = GMUDefaultClusterRenderer(mapView: mapView, clusterIconGenerator: iconGenerator)

    clusterManager = GMUClusterManager(map: mapView, algorithm: algorithm, renderer: renderer)
    clusterManager.cluster()
    clusterManager.setDelegate(self, mapDelegate: self)
} else {
}

// Here's my first custom markers (I don't write here others for simple code)
let firstLocation = CLLocationCoordinate2DMake(48.898902, 2.282664)
let marker = GMSMarker(position: firstLocation)
marker.icon = UIImage(named: "pointeurx1") //Apply custom marker
marker.map = mapView
}

func clusterManager() {...}

推荐答案

您可以检查以下主题: 如何在iOS版GoogleMaps中对自定义图标标记进行聚类 如何在GoogleMaps中从Firebase聚集标记对于iOS

You can check the following topic : How to cluster custom icons markers in GoogleMaps for iOS How to clustered markers from Firebase in GoogleMaps for iOS

您可能会找到一个很好的答案,因为上周我遇到了同样的问题,只需遵循以下建议即可. 希望对您有帮助

You could find a good answer because I had the same issue last week, just follow these advices. Hope it helps you a lot

这篇关于如何在iOS版GoogleMaps中使用自定义标记进行标记聚类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆