Google Maps for iOS,swift - 如何在标记之间显示整个折线?

lif*_*ott 5 google-maps ios google-polyline swift

我想在谷歌地图视图中拟合折线.折线是通过google地图方向api中的overview_polyline获得的.

想知道如何将编码的折线转换成可以使用的东西.我需要在地图视图中拟合折线.我发现要做的就是适合显示所有标记但不显示整个折线的边界.

func fitAllMarkers()
{

    var bounds = GMSCoordinateBounds()

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

    googleMapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds))

}
Run Code Online (Sandbox Code Playgroud)

Man*_* BM 10

对于Swift 2.0 Google地图,要使地图视图适合您绘制的路线的折线:

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))
Run Code Online (Sandbox Code Playgroud)


Yas*_*edi 6

尽管该问题的答案已被接受,

还有一点尚未讨论。

GMSPolyLine具有属性“ .path”,可用于将地图与完整的折线本身绑定。

mapView.animate(with: GMSCameraUpdate.fit(GMSCoordinateBounds(path: self.polyLineObject.path!), withPadding: 10))
Run Code Online (Sandbox Code Playgroud)
  • mapView是GMSMapView()的实例
  • polyLineObject是GMSPolyLine()的实例

有了这种方法,它一定会做的。

因为它为我做了。

希望能帮助到你..