如何将当前位置发送给另一个iPhone用户swift?

时间:2016-07-01 22:06:10

标签: swift mkmapview mapkit currentlocation

我希望能够将我当前的位置发送给另一位iPhone用户。我可以获取当前位置并不断更新我的位置以查看我在地图上的位置但是如何将此信息发送给另一个iPhone用户以便他们可以实时查看我的位置?

代码的基本结构是:

  import UIKit
  import MapKit

  class ViewController: UIViewController,CLLocationManagerDelegate {

@IBOutlet weak var myMapView: MKMapView!


let myLocMgr = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()


    myLocMgr.desiredAccuracy = kCLLocationAccuracyBest
    myLocMgr.requestWhenInUseAuthorization()
    myLocMgr.startUpdatingLocation()
    myLocMgr.delegate = self

}



    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        // get most recient coordinate
        let myCoor = locations[locations.count - 1]

        //get lat & long
        let myLat = myCoor.coordinate.latitude
        let myLong = myCoor.coordinate.longitude
        let myCoor2D = CLLocationCoordinate2D(latitude: myLat, longitude: myLong)

        //set span
        let myLatDelta = 0.05
        let myLongDelta = 0.05
        let mySpan = MKCoordinateSpan(latitudeDelta: myLatDelta, longitudeDelta: myLongDelta)

        let myRegion = MKCoordinateRegion(center: myCoor2D, span: mySpan)

        //center map at this region
        myMapView.setRegion(myRegion, animated: true)

        //add anotation
        let myAnno = MKPointAnnotation()
        myAnno.coordinate = myCoor2D
        myMapView.addAnnotation(myAnno)
    }

0 个答案:

没有答案