Swift 3当前位置到MKPolyline之间的简单位置

时间:2016-06-17 12:37:02

标签: swift swift2 mapkit core-location swift3

您好我有当前位置蓝点显示的工作代码和简单的位置引脚显示我想在它们之间使用MKPolyline我的明确代码在下面进行排列。

import UIKit
import CoreLocation
import MapKit

class ShowMapViewController:  UIViewController,MKMapViewDelegate ,CLLocationManagerDelegate {

    @IBOutlet weak var mapView: MKMapView!


    var showmapListcomming = String()
    let locationManager = CLLocationManager()


    override func viewDidLoad() {
        super.viewDidLoad()


        locationManager.delegate = self
        locationManager.requestLocation()
        locationManager.requestWhenInUseAuthorization()
        locationManager.requestAlwaysAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
        mapView.showsUserLocation = true


        // Show Map

        var myStringArrctakes = showmapListcomming.components(separatedBy: ",")


        let annotation = MKPointAnnotation()
        let latitude:CLLocationDegrees = (myStringArrctakes[6] as NSString).doubleValue
        let longitude:CLLocationDegrees = (myStringArrctakes[5] as NSString).doubleValue
        let latDelta:CLLocationDegrees = 30
        let lonDelta:CLLocationDegrees = 30
        let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
        let locations:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
        let region:MKCoordinateRegion = MKCoordinateRegionMake(locations, span)

        mapView.setRegion(region, animated: false)

        annotation.coordinate = locations
        annotation.title = myStringArrctakes[1]
        annotation.subtitle = "\(myStringArrctakes[2])"
        mapView.addAnnotation(annotation)

    }

    // MARK: - MKMapViewDelegate methods

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

        let annotationView = MKPinAnnotationView()
        return annotationView
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations.last

        let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

        self.mapView.setRegion(region, animated: true)

        if let location = locations.last {
            print("Found User's location: \(location)")
            print("Latitude: \(location.coordinate.latitude) Longitude: \(location.coordinate.longitude)")

        }



    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: NSError) {
        print("Failed to find user's location: \(error.localizedDescription)")
    }



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

我觉得很容易,但我没有解决它。我在等你的想法,我认为这将很快帮助很多人3我在网上找不到这样的东西。

由于

0 个答案:

没有答案