How to handle multiple markers on Google Maps with same location?

前端 未结 5 655
遇见更好的自我
遇见更好的自我 2020-12-24 13:43

I use Google Maps in an app and it is likely that multiple markers are attached to same location where each marker represent a person. In this situation user will not know t

5条回答
  •  一整个雨季
    2020-12-24 14:15

    Giving offset will make the markers faraway when the user zoom in to max. So i found a way to achieve that. this may not be a proper way but it worked very well.

    for loop markers
    {
     //create marker
     let mapMarker = GMSMarker()
     mapMarker.groundAnchor = CGPosition(0.5, 0.5)
     mapMarker.position = //set the CLLocation
     //instead of setting marker.icon set the iconView
     let image:UIIMage = UIIMage:init(named:"filename")
     let imageView:UIImageView = UIImageView.init(frame:rect(0,0, ((image.width/2 * markerIndex) + image.width), image.height))
     imageView.contentMode = .Right
     imageView.image = image
     mapMarker.iconView = imageView
     mapMarker.map = mapView
    }
    

    set the zIndex of the marker so that you will see the marker icon which you want to see on top, otherwise it will animate the markers like auto swapping. when the user tap the marker handle the zIndex to bring the marker on top using zIndex Swap.

提交回复
热议问题