How to put a infowindow on polyline in Google Maps v3?

前端 未结 3 1180
情歌与酒
情歌与酒 2021-01-12 05:51

I want to know how to show infowindow on polyline in using Google Maps Api V3? and to appear in the middle of the polyline ?!

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 06:29

    find the middle point and set your custom view .

    func showPath(polyStr :String){
    
        polyline?.map = nil
        mapView1.reloadInputViews()
        pathDraw = GMSPath(fromEncodedPath: polyStr)!
        polyline = GMSPolyline(path: pathDraw)
    
        polyline?.strokeWidth = 4.0
        polyline?.strokeColor = UIColor.init(red: 247/255.0, green: 55/255.0, blue: 76/255.0, alpha: 1.0)
        polyline?.map = mapView1
    
    
        let poinsCount = pathDraw.count()
        let midpoint = pathDraw.coordinate(at: poinsCount)
    
        DispatchQueue.main.async
        {
            self.addMarkerPin(corrdinate: midCordinate, distance: "10 min")
        }
    
    }
    func addMarkerPin(corrdinate:CLLocationCoordinate2D, distance: String)
    {
        let marker = GMSMarker()
        marker.position = corrdinate
    
        PathTimeView = PathInfoView.loadFromNib() //here i am load Xib file, you can use your custom view 
        let DynamicView=PathTimeView
        DynamicView.timelbl.text = distance
    
        UIGraphicsBeginImageContextWithOptions(DynamicView.frame.size, false, UIScreen.main.scale)
        DynamicView.layer.render(in: UIGraphicsGetCurrentContext()!)
        let imageConverted: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
        UIGraphicsEndImageContext()
    
        marker.icon = imageConverted
        marker.map = self.mapView1
        marker.infoWindowAnchor = CGPoint(x: -1900 , y: -2000)
    }
    

提交回复
热议问题