2016-12-28 116 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