How do I manage and group multiple locations at the same address?

I use google maps with clusters in an iOS app developed in Swift. There are some markers on the Google map with the same latitude and longitude. When the user approaches the point where there are only two places in the cluster and increase slightly when markers are displayed, these markers sparkle (flicker) and quickly overlap each other (one above the other).

How can I do it when the user zooms in and there are only two tokens in the cluster with the same addresses and locations so as not to break them into clusters into tokens so that they remain clustered? Is there a way to get tokens from the cluster (which are). Thank you for your responses.

+5
source share
5 answers

I had the same problem to overcome the flashing effect that it gave very slight variations for similar latitude and longitude values.

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 } 

Just call checkIfMutlipleCoordinates whenever you set the marker position

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

I recently ran into the problem of multiple events at the same latitude and longitude. I believe that changing insignificance in latitude and longitude is an alternative, but it can violate your business model if you create a very specific application based on location.

One solution has a callout view in which you can list several events when you click a marker. Save your own marker image with some icon number in the upper right corner (preferably) and when you press the marker, show the leader.

You can refer to the screenshot.

enter image description here

Something like this if this place has several events. You can simply show that everything is happening, and then when you click the marker, you can show the leader of other events. You can make a callout using a tableView or something like that.

I hope you get some idea.

enter image description here

+2
source

I apologize for being late for the party, but: since version 1.4.0 (July 2013), the SDK in GMSOverlay (subclasses of GMSMarker) has a property called 'zIndex'.

As stated in the docs:

Overlays with a higher zIndex value will be displayed on top of layers and overlays with a lower zIndex value.

Equal values ​​result in an undefined drawing order.

Flickering may be due to the fact that both markers have zIndex == 0

Anyway, this is what works for me.

+2
source

Known behavior of the Google Maps iOS SDK

If you create a custom marker and use the iconView property to change the image of the icon, it will give a blinking effect if the coordinates are exactly the same. This is a known google maps iOS SDK issue. Try using the default marker and see if the problem persists.

+1
source

Here is a Swift 4 solution extending CLLocationCoordinate2D based on Arpit Jain answer:

 extension CLLocationCoordinate2D { mutating func variateForEqual(coordinates: [CLLocationCoordinate2D]) { var variatedLatitude = latitude var variatedLongitude = longitude let filteredPositions = coordinates.filter { $0 == self } if filteredPositions.isNotEmpty { let variation = Double.random(in: -0.01...0.01) / 1500 variatedLatitude = latitude + variation variatedLongitude = longitude + variation } self = CLLocationCoordinate2D(latitude: variatedLatitude, longitude: variatedLongitude) } } ' 
0
source

Source: https://habr.com/ru/post/1270014/


All Articles