如何在ios Swift的GMSMapView中绘制类似uber的弯曲折线,facebook

问题描述 投票:0回答:1

我想在两个端点之间绘制一条曲线(类似facebook,uber)。

我尝试过此代码https://stackoverflow.com/a/53569754/4693326,但未获得确切结果。我还附加了该文件以供参考。是否有任何想法?

enter image description here

ios swift iphone polyline
1个回答
0
投票

您尝试过这个吗:

  let origin = "\(37.778483),\(-122.513960)"
    let destination = "\(37.706753),\(-122.418677)"
    let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving&key=[YOUR-API-KEY]"

    Alamofire.request(url).responseJSON { response in
        let json = JSON(data: response.data!)
        let routes = json["routes"].arrayValue

        for route in routes
        {
            let routeOverviewPolyline = route["overview_polyline"].dictionary
            let points = routeOverviewPolyline?["points"]?.stringValue
            let path = GMSPath.init(fromEncodedPath: points!)

            let polyline = GMSPolyline(path: path)
            polyline.strokeColor = .black
            polyline.strokeWidth = 10.0
            polyline.map = mapViewX

        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.