【问题标题】:Drawing path with google direction api使用谷歌方向api绘制路径
【发布时间】:2017-03-19 17:24:32
【问题描述】:

我正在尝试使用 google direction api 在多个地方之间绘制路径,但问题是当我缩放地图时,路径未正确绘制。

我正在点击这个 api 并从 JSON 的响应中绘制带有“overview_polyline”点的路径。

https://maps.googleapis.com/maps/api/directions/json?origin=(startLocationLat),(startLocationLong)&destination=(endLocationLat),(endLocationLong)&waypoints=(self.wayPointBetweenLocations)&key=AIzaSyCK0dxRGRlFqM84SUM3zbVQAdbXEXtN-x0&mode=driving

let polygon = GMSPolygon()
polygon.path = GMSPath(fromEncodedPath: "\(self.overview_points)")

请帮我解决这个问题。 谢谢

【问题讨论】:

    标签: ios google-maps swift3


    【解决方案1】:

    使用GMSPolyline 而不是GMSPolygon 来绘制路径。

    示例

        let path = GMSPath(fromEncodedPath: "\(self.overview_points)")
        let directionPolyline = GMSPolyline(path: path)
        directionPolyline.strokeColor = UIColor.blue
        directionPolyline.strokeWidth = 3
        directionPolyline.map = self.mapView
    

    【讨论】:

      【解决方案2】:

      尝试使用Google Maps Roads API 部分Snap to Roads 作为来自 JSON 响应的点。

      【讨论】:

        猜你喜欢
        • 2019-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多