Google Maps for iOS,swift - 如何在标记之间显示整个折线? [英] Google Maps for iOS, swift - How to show entire polyline between markers?

查看:192
本文介绍了Google Maps for iOS,swift - 如何在标记之间显示整个折线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在Google地图视图中放置折线。多段线是通过Google地图方向api中的overview_polyline获取的。

I am trying to fit a polyline in the google map view. The polyline was acquired through overview_polyline in the google maps directions api.

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

Wondering how I would be able to convert an encoded polyline into something that can be worked with. I need to fit the polyline in the map view. All i have found out to do is fit the bounds to show all markers but not showcase the entire polyline.

func fitAllMarkers()
{

    var bounds = GMSCoordinateBounds()

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

    googleMapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds))

}


推荐答案

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

For Swift 2.0 Google Maps, to make your map view fit the polyline of the route you are drawing:

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))

这篇关于Google Maps for iOS,swift - 如何在标记之间显示整个折线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆