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)
尽管该问题的答案已被接受,
还有一点尚未讨论。
GMSPolyLine具有属性“ .path”,可用于将地图与完整的折线本身绑定。
mapView.animate(with: GMSCameraUpdate.fit(GMSCoordinateBounds(path: self.polyLineObject.path!), withPadding: 10))
Run Code Online (Sandbox Code Playgroud)
有了这种方法,它一定会做的。
因为它为我做了。
希望能帮助到你..
归档时间: |
|
查看次数: |
8423 次 |
最近记录: |