ios - 用google direction api绘制路径

标签 ios google-maps swift3

enter image description here

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

我正在点击此 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)")

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

最佳答案

使用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

关于ios - 用google direction api绘制路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42889685/

相关文章:

iphone - 同一个委托(delegate)上的多个 UIActionSheets

ios - 我想在 Xcode 上使用 Swift 让我的黑暗模式同时在所有 View Controller 上工作。我该怎么做?

javascript - 如何在 Google map 上旋转叠加层图像?

ios - dyld : Library not loaded: @rpath/Stripe. 框架/Stripe

ios - 在哪里存储来自服务器的解码 JSON 数组以及如何在 viewControllers 中全局访问它?

ios - 如何自动设置约束以使 UIView 之间的距离统一?

安卓 : Count markers in the map

javascript - 地理位置 - 将纬度和经度值分配给变量

ios - 如何设置本地通知在首次设置通知后每秒触发一次?

ios - 获取使用 Storyboard创建的 View Controller 的属性