Praveen Kumar
Praveen Kumar

Reputation: 567

GMSMarker infowindow content(snippet) not updating

I have an array in which each element has Latitude Longitude and some other values in it to draw marker on map. I'm using the following code to update the snippet, position and icon of GMSMarker. I'm using a UISlider to iterate through the array. When I do this the icon and position of the marker gets updated and the InfoWindow of the marker not updating. It shows only the old content. But when I deselect and select it again now it shows correct infowindow content. I have tried to use tracksInfoWindowChanges, but it's not working.

 @IBAction func progressChanged(_ sender: UISlider) {

    let iVal = Int(sender.value)

    if iVal < progressList.count {
        let str = progressList[iVal]
        let arr = str.components(separatedBy: "!")
        let lat = Double(arr[4])!
        let lng = Double(arr[5])!
        let pos = CLLocationCoordinate2DMake(lat, lng)
        let fRotation = Float(arr[9])
        let rotation = CGFloat(fRotation!)
        let strTime = arr[0]
        let idleFlag = arr[1]
        let strSpeed = arr[2]
        let strName = arr[3]

        proMarker.position = pos
        proMarker.title = strName

        if idleFlag == "Y" {
            proMarker.snippet = strSpeed + "!" + strTime + "!" + "idle"
            proMarker.tracksInfoWindowChanges = true

            let markerImage = UIImage(named: "arrow_red")
            let rotated = markerImage?.imageRotatedByDegrees(rotation, flip: false)

            proMarker.icon = rotated

        } else {
            proMarker.snippet = strSpeed + "!" + strTime + "!" + "moving"
            proMarker.tracksInfoWindowChanges = true

            let markerImage = UIImage(named: "arrow_green")
            let rotated = markerImage?.imageRotatedByDegrees(rotation, flip: false)

            proMarker.icon = rotated
        }

        proMarker.groundAnchor = CGPoint(x: 0.5, y: 0.5)

        let dTime = sdf5.date(from: strTime)
        let sTime = sdf6.string(from: dTime!)

        hTime.text = sTime
        hSpeedIdle.text = strSpeed + " km/h"

    }

}

Please help me solve my problem.

Upvotes: 2

Views: 240

Answers (2)

Efren
Efren

Reputation: 4887

As mentioned in a comment, it may be that you are not making new markers, or if you are, you need to remove the map from the old markers (marker.map = nil). So when you click on overlapped markers, the infowindows will sequentially appear.

Upvotes: 0

ami rt
ami rt

Reputation: 933

This is not a correct way to add lat_long, You should add marker_obj into array because each marker contain all related info, and it can help you to reduce such type of length of code.

Upvotes: 0

Related Questions