如何在swift4中显示GMSPolygon的标题

时间:2019-07-02 13:46:51

标签: swift google-maps

这是我的代码,显示多边形,但标题未显示在任何地方。

       func showGeofense(zoomeffectTo:Int)  {
            for item in self.Geofenses
            {
                let polygon = GMSPolygon()
                let path = GMSMutablePath()
                var cord = CLLocationCoordinate2D(latitude: item.coordinatesArray[0].lat, longitude: item.coordinatesArray[0].lng)
                for o in item.coordinatesArray
                {
                    path.add(CLLocationCoordinate2D(latitude: o.lat, longitude: o.lng))
                }

                polygon.path = path
                //            polygon.fillColor = #colorLiteral(red: 0.9474907517, green: 0.2350950539, blue: 0.1785519123, alpha: 0.24)
                var color  = item.polygonColor
                color.remove(at: color.startIndex)
                print(color)
                var col:Int = Int(color) ?? 0xFFFFFF
                polygon.isTappable = true
                polygon.strokeColor = UIColor(hex: col).withAlphaComponent(0.3)
                polygon.strokeWidth = 5
                polygon.title = item.name
                polygon.map = googlemapView

                if zoomeffectTo == 3
                {
                    self.moveCameraTo(pos: cord)
                }
            }
        }
                // this is printing the title when i click on ploygon
                     func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
                            print(overlay.title)

                        }              

上面的功能didtap覆盖既触发又打印标题,但是我找不到任何显示地理围栏标题或描述的方法。

1 个答案:

答案 0 :(得分:0)

检查GoogleMaps.framework-> GMSPolygon我发现它的父对象是GMSOverlay。

关于标题的描述,我可以看到:

/**
 * Title, a short description of the overlay. Some overlays, such as markers, will display the title
 * on the map. The title is also the default accessibility text.
 */
@property(nonatomic, copy, nullable) NSString *title;

似乎只有标记会显示标题...