ios - GMSMarker 信息窗口未更新

标签 ios swift google-maps uiviewcontroller google-maps-markers

我正在使用谷歌地图和它的标记。为了在标记上显示信息,我使用自定义 View 来显示它。但是一旦我初始化它,值就不会更新。
下面是我的代码。

func mapView(_ mapView: GMSMapView!, markerInfoWindow marker: GMSMarker) -> UIView? {
        let location = CLLocation(latitude: marker.position.latitude, longitude: marker.position.longitude
        var markerView : MarkerInfoView = Bundle.main.loadNibNamed("MarkerInfoView", owner: self, options: nil)![0] as! MarkerInfoView
        let geoCoder = CLGeocoder()
        geoCoder.reverseGeocodeLocation(location) { (placemarkers, error) in
            if let placemarker = placemarkers?.last {
                var strAddress = ""
                if let str = placemarker.name {
                    strAddress += str
                }
                if let str = placemarker.subAdministrativeArea {
                    strAddress += ", " + str
                }
                print(strAddress)
                markerView.deviceInfo.text = "HELLO TESTING"
            print(markerView.deviceInfo.text!) // This is printing "HELLO TESTING", but not updating on marker
                markerView.addressInfo.text = strAddress
            }
        }
        if let str = marker.snippet {
            markerView.deviceInfo.text = str.components(separatedBy: "|")[0]
            //TODO: add time
            markerView.dateInfo.text = str.components(separatedBy: "|")[1]
//            markerView.addressInfo.text = ""
        }
        else {
            markerView.deviceInfo.text = ""
            markerView.dateInfo.text = ""
//            markerView.addressInfo.text = ""
        }
        return markerView

    }

请指导我如何更新 infoWindow 中的值。

最佳答案

试试这个代码

// MARKER - GoogleMaps delegate
func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView? {
    print("title \(markerTitle)")

    var infoView:UIView!

    infoView = UIView()
    infoView.frame = CGRect(x: 0, y: 0, width: 300, height: 75)
    infoView.backgroundColor = .black

    let orderIDLbl = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 75))
    orderIDLbl.text = "markerTitle" //Your title here
    orderIDLbl.font = UIFont.systemFont(ofSize: 15)
    orderIDLbl.textAlignment = NSTextAlignment.center
    orderIDLbl.numberOfLines = 0
    orderIDLbl.textColor = .white
    infoView.addSubview(orderIDLbl)

    return infoView
}

关于ios - GMSMarker 信息窗口未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52735031/

相关文章:

iphone - 在iOS 5中更新进度条

ios - 以编程方式设置 Xcode 模拟器、键盘和 Touch ID 设置,用于 UI 测试

swift - mixLatest 在 Just 与 Future 中具有不同的行为

javascript - 限制 google 位置条目到 AngularJS 中的建议列表

ios - 迦太基和谷歌地图

javascript - 如何在 Google Maps API 中获取 KML 放置标记值?

ios - iOS:移除我随机放置的图片

ios - 将 Game over 实现到 swift 游戏中

iphone - 无法在 TableView Swift 上显示任何内容

javascript - 为什么触摸事件监听器似乎阻止了在 iphone 或 ipad 上选择谷歌翻译语言?