Swift 如何连接两个注释点?

Swift 如何连接两个注释点?,swift,annotations,swift2,mapkit,mapkitannotation,Swift,Annotations,Swift2,Mapkit,Mapkitannotation,我从Address text field和toAddress text fields传递了两个值,我需要像路由一样连接两个注释点。我不需要任何基于api的说明。只是需要连接 import UIKit import MapKit import CoreLocation import Contacts class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { @IBOutlet w

我从Address text field和toAddress text fields传递了两个值,我需要像路由一样连接两个注释点。我不需要任何基于api的说明。只是需要连接

import UIKit
import MapKit
import CoreLocation
import Contacts

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

@IBOutlet weak var fromAddress: UITextField!
@IBOutlet weak var toAddress: UITextField!
@IBOutlet weak var map: MKMapView!

let locationManager = CLLocationManager()
var location = CLLocation!.self

@IBAction func getDirection(sender: AnyObject) {

    ConnectingFromAndTo(fromAddress.text!)
    ConnectingFromAndTo(toAddress.text!)
 }


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.}
}

func ConnectingFromAndTo(address: String){

    CLGeocoder().geocodeAddressString(address, completionHandler:
        {(placemarks, error) in

            if error != nil {
                print("Geocode failed with error: \(error!.localizedDescription)")
            } else if placemarks!.count > 0 {
                let placemark = placemarks![0]
                let location = placemark.location


                let annotation = MKPointAnnotation()
                annotation.coordinate = location!.coordinate
                annotation.title = "\(placemark.locality!)"
                annotation.subtitle = "\(placemark.country!)"
                self.map.addAnnotation(annotation)

                self.map.setRegion(MKCoordinateRegionMake(CLLocationCoordinate2DMake (placemark.location!.coordinate.latitude, placemark.location!.coordinate.longitude), MKCoordinateSpanMake(0.002, 0.002)), animated: true)


            }
    })


}


}

您可以轻松获得这两个注释坐标,并在地图视图上绘制MKGeodisicPoliline,如下面的代码所示。多段线将有2个注释

 var geodesicPolyline = MKGeodesicPolyline(coordinates: &coordinates[0], count: 2)
map.addOverlay(geodesicPolyline)

其中坐标数组包含注释的位置坐标对象。

Hi如何传递存储在位置管理器函数func locationManager(管理器:CLLocationManager,didUpdateLocations locations:[CLLocation])中的坐标我需要连接存储在位置数组中的坐标,第n个和第n-1个
 var geodesicPolyline = MKGeodesicPolyline(coordinates: &coordinates[0], count: 2)
map.addOverlay(geodesicPolyline)