2016-12-28 169 views
0

期间绘制与谷歌地图折线我发现下面的运行过程中绘制路径/走与苹果地图斯威夫特3运行

extension NewRunViewController: MKMapViewDelegate { 
    func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! { 
    if !overlay.isKindOfClass(MKPolyline) { 
     return nil 
    } 

    let polyline = overlay as! MKPolyline 
    let renderer = MKPolylineRenderer(polyline: polyline) 
    renderer.strokeColor = UIColor.blueColor() 
    renderer.lineWidth = 3 
    return renderer 
    } 
} 

但是我试图与谷歌地图来做到这一点,可以”找到解决方案。 许多答案适用于Apple地图,但在Google地图上没有太多答案。

+0

你想使用用户位置绘制折线? –

+0

@RajeshkumarR是的,他正在移动时绘制折线 – asheyla

+0

在locationManager的委托方法'didUpdateLocations'中使用像这样的'path.add(locations.last.coordinate)' –

回答

0

试试这个

let path = GMSMutablePath() 
//Change coordinates 
path.add(CLLocationCoordinate2D(latitude: -33.85, longitude: 151.20)) 
path.add(CLLocationCoordinate2D(latitude: -33.70, longitude: 151.40)) 
path.add(CLLocationCoordinate2D(latitude: -33.73, longitude: 151.41)) 
let polyline = GMSPolyline(path: path) 
polyline.strokeColor = UIColor.blue 
polyline.strokeWidth = 3.0 
polyline.map = mapView