ios - 适用于 iOS 的 Google map ,swift - 如何在标记之间显示整条多段线?

标签 ios swift google-maps google-polyline

我正在尝试在谷歌地图 View 中设置多段线。折线是通过 google maps directions api 中的 overview_polyline 获取的。

想知道如何将编码的多段线转换成可以使用的东西。我需要在 map View 中调整多段线。我发现要做的就是调整边界以显示所有标记,但不显示整条多段线。

func fitAllMarkers()
{

    var bounds = GMSCoordinateBounds()

    for marker in markers
    {
        bounds = bounds.includingCoordinate(marker.position)
    }

    googleMapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds))

}

最佳答案

对于 Swift 2.0 Google map ,要使您的 map View 适合您正在绘制的路线的多段线:

let path: GMSPath = GMSPath(fromEncodedPath: route)!
    routePolyline = GMSPolyline(path: path)
    routePolyline.map = mapView


    var bounds = GMSCoordinateBounds()

    for index in 1...path.count() {
        bounds = bounds.includingCoordinate(path.coordinateAtIndex(index))
    }

    mapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds))

关于ios - 适用于 iOS 的 Google map ,swift - 如何在标记之间显示整条多段线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35095149/

相关文章:

swift - 在覆盖 View 上启用用户交互

ios - UIView borderWidth 不可见

javascript - 用于地理空间操作的 Node.js 库

ios - 为什么 CoreLocation 无法获取新的 GPS 数据而 Mapkit 显示旧的 GPS 数据

google-maps - -canOpenURL : failed for URL: "comgooglemaps://" - error: "The operation couldn’ t be completed.(OSStatus 错误 -10814。)”

arrays - 如何使用select过滤一个数组中的Google Maps标记?

ios - 台风注入(inject)和设置委托(delegate)

ios - 如何在 UITableView 的部分标题中设置字体颜色?

android - 在 Google SDK 内部开发与外部开发

ios - 为什么 removeAllObservers() 在 deinit 中不起作用?