我正在尝试在谷歌地图视图中拟合一条折线。折线是通过谷歌地图方向API中的overview_polyline获取的。
想知道如何将编码的折线转换为可以使用的东西。我需要使折线适合地图视图。我发现要做的就是适应边界以显示所有标记,但不显示整个折线。
func fitAllMarkers()
{
var bounds = GMSCoordinateBounds()
for marker in markers
{
bounds = bounds.includingCoordinate(marker.position)
}
googleMapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds))
}
对于 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))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)