本文介绍了如何处理同一地址上的多个位置并将它们集群?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在Swift中开发的iOS应用程序中使用带有集群的谷歌地图。在谷歌地图上有一些标记具有相同的经度和纬度。当用户放大到只有两个位置的位置时,当显示标记时放大一点点,这些标记会发生闪烁(闪烁),并且彼此快速叠加(一个在另一个之上)。

I'm using google maps with clusters in iOS application developed in Swift. On google map there are some markers with the same latitude and longitude. When user zooms in to the point where are only two places in cluster and zooms a little bit more when markers are shown, these markers are glitched (flickering) and they overlay rapidly each other (one over another).

当用户放大时,我该如何实现这一功能,并且群集中只有两个标记具有相同的地址和位置,不会将它们从群集中划分为标记,因此他们保持聚集?有没有一种方法可以从集群中获取标记感谢您的回答。

How can I accomplish when user zooms in, and there are only two markers in cluster with same address and location, to not split them out of cluster into markers, so that they stay clustered? Is there a way to get markers from (that are in) the cluster Thanks for your answers.

推荐答案

我有同样的问题,为了克服闪烁效应,它对经度和纬度的相似值给予了非常小的变化。

I had the same issue , to overcome flashing effect it had given very minor variation to similar values of latitude and longitude.

func checkIfMutlipleCoordinates(latitude : Float , longitude : Float) -> CLLocationCoordinate2D{

        var lat = latitude
        var lng = longitude

        // arrFilterData is array of model which is giving lat long

        let arrTemp = self.arrFilteredData.filter {

            return (((latitude == $0.latitute) && (longitude == $0.longitute)))
        }

        // arrTemp giving array of objects with similar lat long

        if arrTemp.count > 1{
            // Core Logic giving minor variation to similar lat long

            let variation = (randomFloat(min: 0.0, max: 2.0) - 0.5) / 1500
            lat = lat + variation
            lng = lng + variation
        }
        let finalPos = CLLocationCoordinate2D(latitude: CLLocationDegrees(lat), longitude: CLLocationDegrees(lng))
        return  finalPos
    }

 func randomFloat(min: Float, max:Float) -> Float {
        return (Float(arc4random()) / 0xFFFFFFFF) * (max - min) + min
    }

每当您设置标记位置时,只需调用 checkIfMutlipleCoordinates 即可

Simply call checkIfMutlipleCoordinates whenever you set marker position

 let position = checkIfMutlipleCoordinates(latitude: yourlatitute!, longitude: yourlongitute!)

这篇关于如何处理同一地址上的多个位置并将它们集群?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:04