IOS Swift Google map 截断标题

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

我使用下面的代码将带有标题的标记添加到 map 中。

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()

                })
            }
        }
    }

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

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

Strings that are longer than the width of the info window are automatically wrapped over several lines. Very long messages may be truncated.

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

enter image description here

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

最佳答案

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

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

这对我来说神奇地有效。

关于IOS Swift Google map 截断标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49123654/

相关文章:

ios - Swift 3 自定义单元带来错误

ios - Assets 目录编译错误

swift - 快速解析数据

javascript - Google map API key v3 的使用

google-maps - 标记拖动点击事件谷歌地图

android - 代号一 - ReplaceAndWait() 不起作用?

ios - 是否可以 'split' UIViewController 并将部件动画到所选单元格的顶部和底部

swift - dispatch.async() 只运行 1 行代码

swift - Realm 迁移 - 更改类的名称(对于复杂类)

angularjs - 模态内的 NgMap(谷歌地图) - 不显示第二次