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
}
Simply call checkIfMutlipleCoordinates
whenever you set marker position
let position = checkIfMutlipleCoordinates(latitude: yourlatitute!, longitude: yourlongitute!)
I am sorry to be late for the party but: as of version 1.4.0(July 2013) of the SDK there's a property on GMSOverlay(Which GMSMarker subclasses) named 'zIndex'.
As stated in the docs:
Higher zIndex value overlays will be drawn on top of lower zIndex value tile layers and overlays.
Equal values result in undefined draw ordering.
The flickering might be because both markers have zIndex == 0
Anyways, that's what worked for me.
I recently faced this issue of multiple happenings on same latitude and longitude. I believe changing minor in latitude and longitude is an alternative but this may violate your business model if you are making a very specific location based application.
One solution is having a callout like view where you can list your multiple happenings when you tap on marker. Keep a custom image of marker with some badge number on top right(preferably) and on tapping the marker, show a callout.
You can refer the screenshot.
Something like this if this place has multiple happenings. You can just show any one happening and then on tap of marker you can show a callout of other happenings. You can make a callout by using a tableView or something.
Hope you get some idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With