Google iOS、swift 的地图 - 如何显示标记之间的整条折线?
Google Maps for iOS, swift - How to show entire polyline between markers?
我正在尝试在 google 地图视图中添加多段线。折线是通过 overview_polyline 在 google 地图方向 api 中获取的。
想知道如何将编码的多段线转换成可以使用的东西。我需要在地图视图中调整多段线。我发现要做的就是调整边界以显示所有标记,但不显示整条多段线。
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))
**For Swift 3.0 Google Maps, to make your map view fit the polyline of the route you are drawing:**
func fitAllMarkers(_path: GMSPath) {
var bounds = GMSCoordinateBounds()
for index in 1..._path.count() {
bounds = bounds.includingCoordinate(_path.coordinate(at: index))
}
mapView.animate(with: GMSCameraUpdate.fit(bounds))
}
虽然问题有一个可接受的答案,
还有一点没有讨论
GMSPolyLine 有一个 属性“.path”,可用于将地图与完整的折线本身绑定。
mapView.animate(with: GMSCameraUpdate.fit(GMSCoordinateBounds(path: self.polyLineObject.path!), withPadding: 10))
- mapView 是 GMSMapView() 的一个实例
- polyLineObject 是 GMSPolyLine() 的一个实例
通过这种方法,它肯定能完成工作。
因为它已经为我完成了..
希望对您有所帮助..
您可以根据地图视图中显示的路线或线路缩放地图。这样您的路线就会显示在 mapView 范围内。
let bounds = GMSCoordinateBounds(path:path! )
self.mapView!.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 50.0))
这里path是路由的GMSPath,mapView是GmsMapView
我正在尝试在 google 地图视图中添加多段线。折线是通过 overview_polyline 在 google 地图方向 api 中获取的。
想知道如何将编码的多段线转换成可以使用的东西。我需要在地图视图中调整多段线。我发现要做的就是调整边界以显示所有标记,但不显示整条多段线。
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))
**For Swift 3.0 Google Maps, to make your map view fit the polyline of the route you are drawing:**
func fitAllMarkers(_path: GMSPath) {
var bounds = GMSCoordinateBounds()
for index in 1..._path.count() {
bounds = bounds.includingCoordinate(_path.coordinate(at: index))
}
mapView.animate(with: GMSCameraUpdate.fit(bounds))
}
虽然问题有一个可接受的答案,
还有一点没有讨论
GMSPolyLine 有一个 属性“.path”,可用于将地图与完整的折线本身绑定。
mapView.animate(with: GMSCameraUpdate.fit(GMSCoordinateBounds(path: self.polyLineObject.path!), withPadding: 10))
- mapView 是 GMSMapView() 的一个实例
- polyLineObject 是 GMSPolyLine() 的一个实例
通过这种方法,它肯定能完成工作。
因为它已经为我完成了..
希望对您有所帮助..
您可以根据地图视图中显示的路线或线路缩放地图。这样您的路线就会显示在 mapView 范围内。
let bounds = GMSCoordinateBounds(path:path! )
self.mapView!.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 50.0))
这里path是路由的GMSPath,mapView是GmsMapView