【问题标题】:IOS Swift Google Maps truncate the titleIOS Swift Google Maps 截断标题
【发布时间】:2018-08-13 21:17:23
【问题描述】:

我正在使用以下代码向地图添加带有标题的标记。

func showAllMarker(){
        loadLocatons(){
            completion in
            if completion {
                super.hideLoading()
                self.mapView.clear()
                self.circle(withRadius: self.Defradius, circleCenter: self.myLocation2D)
                for point in self.mobLocationData {

                    if point.status == ConstantValues.activeStatus{
                        let marker = GMSMarker()
                        let latitude  = point.latitude
                        let longitude  = point.longitude
                        let position = CLLocationCoordinate2D(latitude: NSString(string: latitude!).doubleValue, longitude: NSString(string: longitude!).doubleValue)

                        marker.position = position
                        marker.title = point.description

                        marker.userData = LocationMarkerData(id: point.id!, address: point.address!)
                        marker.map = self.mapView
                    }
                }                
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
                    let camera = GMSCameraPosition.camera(withLatitude: self.myLocation.coordinate.latitude, longitude: self.myLocation.coordinate.longitude, zoom: 10.5,bearing: 350,viewingAngle: 10)
                    CATransaction.begin()
                    CATransaction.setValue(1.5, forKey: kCATransactionAnimationDuration)
                    self.mapView.animate(to: camera)
                    CATransaction.commit()

                })
            }
        }
    }

有时点击标记时不会显示完整的标题。它会截断标题。见下图。

在谷歌地图文档中,它说只有很长的消息可能会被截断。

长于信息窗口宽度的字符串是 自动换行多行。很长的消息可能是 被截断。

但图片中上述标记的标题是“test”。所以这不是一个很长的标题。还有一些其他标记的标题比这更长,并且它们不会被截断。见下图

那么有人可以解释一下我做错了什么以及如何纠正这个问题吗?

【问题讨论】:

  • @udi 尝试以这种方式在 marker.sn-p = point.description 中添加您的文本
  • @RajeshKumarR 没用
  • @ravi.p 片段也被截断
  • 我不认为 google map sdk 会截断标题。这似乎是渲染的问题(并且只出现在特定的设备上并且只出现在特定的小标题上)。有时 UILabel 的宽度有点太小(1 像素),所以 iOS 会截断标签的文本并放置三个点。连我都帮不上你的解决办法,也许有可能得到底层的 UILabel 并增加它的宽度。

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


【解决方案1】:

只需将单词的第一个字母大写如下:

let outlet_name = "\(DataDict["routeName"] ?? "")".lowercased()
marker.title = outlet_name.capitalizingFirstLetter()

这对我来说很神奇。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 2011-10-30
    相关资源
    最近更新 更多