在地图视图中显示当前位置时,如何显示蓝点而不是 Pin?

How do you show a blue dot instead of a Pin when showing current location in mapview?

在地图视图中显示当前位置时,如何显示蓝点而不是 Pin 图?目前代码显示了一个红色图钉,当用户四处移动时显示用户当前位置。我如何将其转换为苹果使用的蓝点?

  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)
    }



@IBAction func stop(sender: AnyObject) {
    myLocMgr.stopUpdatingLocation()
}


@IBAction func resume(sender: AnyObject) {
    myLocMgr.startUpdatingLocation()
}




override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

}

self.myMapView.showsUserLocation = true

showsUserLocation is what you need. It's MKMapView 属性 在 viewDidLoad 中设置或使用 IB(如果可能)。您不需要在 LocationManager 的委托 didUpdateLocations 中做任何额外的事情,只需将其设置为 MKMapView 将完成其余的事情