我有一個數組,其中每個元素都有Latitude
Longitude
以及其他一些值,可以在地圖上繪製標記。我正在使用以下代碼更新GMSMarker
的片段,位置和圖標。我正在使用UISlider
來遍歷數組。當我這樣做時,標記的圖標和位置會更新,標記的InfoWindow
不會更新。它只顯示舊內容。但是,當我取消選擇並再次選擇它時,它會顯示正確的infowindow內容。我試圖使用tracksInfoWindowChanges
,但它不起作用。GMSMarker infowindow content(snippet)not updating
@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"
}
}
請幫我解決我的問題。
這不是問題在這裏。標記位置和圖標更新沒有任何問題。只有infowindow沒有更新。 –
好吧,嘗試在if {}條件下創建'proMarker'的新實例。 –