CLLocationManagerを使用して、いくつかのメーターを移動した後にユーザーの場所を更新できると思います。私はあなたの場所を更新するために既にCLLocationManagerを持っていると思いますか?配列の中にドットを保存することができます(Aの位置から始まり、Cの位置で終わる)。その後、点を使用して線を描くことができます。 Google Map APIには線を描画するメソッドがあると思います。 (リンクのコードがにObjCである)
Here is a link from SO
しかし、コードを提供するために、私はスウィフト3.0にあなたのためにそれを提供します:そこここにそのための答えです
override func viewDidLoad() {
super.viewDidLoad()
//This is a dummy location, you'd add locations to it using the
// func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
let location:CLLocation = CLLocation(latitude: 200, longitude: 100)
let locationArray:Array<CLLocation> = [location]
let camera:GMSCameraPosition = GMSCameraPosition.camera(withLatitude: (locationArray.first?.coordinate.latitude)!, longitude: (locationArray.first?.coordinate.longitude)!, zoom: 2)
//You can obtain the Lat and Long for above from the list of arrays of locations you saved
//You can use the .first or .last on the array (I used first)
let mapview:GMSMapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
let path:GMSMutablePath = GMSMutablePath()
for nextLocation in locationArray {
if locationArray.index(of: nextLocation) != 0 {
//You dont want to use the first one as you've already done it
//so you start with 1
path.addLatitude(nextLocation.coordinate.latitude, longitude: nextLocation.coordinate.longitude)
}
}
let polyline:GMSPolyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor.red
polyline.strokeWidth = 2
polyline.map = mapview
self.view = mapview
//I personally prefer view.addSubview(mapview)
}