Was ich habe, ist ein einfaches Kartenlayout Wo es den aktuellen Benutzer Standort findet und dann einen Pin an diesem aktuellen Ort platziert. Ich denke, ich habe den richtigen Code, aber ich sehe den Pin nicht, wenn ich meinen Standort leite.Warum kann ich meine Anmerkungen nicht auf der Karte anzeigen lassen?
import MapKit
import UIKit
class ViewController: UIViewController, CLLocationManagerDelegate {
var coreLocationManager = CLLocationManager()
var locationManager:LocationManager!
//allowing permission to use your location
@IBOutlet weak var Map: MKMapView!
@IBOutlet weak var myLocation: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
coreLocationManager.delegate = self
locationManager = LocationManager.sharedInstance
let authorizationCode = CLLocationManager.authorizationStatus()
if authorizationCode == CLAuthorizationStatus.NotDetermined && coreLocationManager.respondsToSelector("requestAlwaysAuthorization") || coreLocationManager.respondsToSelector("requestWhenInUseAuthorization"){
if NSBundle.mainBundle().objectForInfoDictionaryKey("NSLocationAlwaysUsageDescription") != nil {
coreLocationManager.requestAlwaysAuthorization()
}else{
print("No description provided")
}
}else{
getLocation()
}
}
//getting your location
func getLocation(){
locationManager.startUpdatingLocationWithCompletionHandler { (latitude, longitude, status, verboseMessage, error) ->() in
self.displayLocation(CLLocation(latitude: latitude, longitude: longitude))
}
}
func displayLocation(Location:CLLocation){
Map.setRegion(MKCoordinateRegion(center: CLLocationCoordinate2DMake(Location.coordinate.latitude, Location.coordinate.longitude), span: MKCoordinateSpanMake(0.05, 0.05)), animated: true)
let locationPinCoord = CLLocationCoordinate2D(latitude: Location.coordinate.latitude, longitude: Location.coordinate.longitude)
let annotation = MKPointAnnotation()
annotation.coordinate = locationPinCoord
//SHOW POINTS
Map.addAnnotation(annotation)
Map.showAnnotations([annotation], animated: true)
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status != CLAuthorizationStatus.NotDetermined || status != CLAuthorizationStatus.Denied || status != CLAuthorizationStatus.Restricted{
}
}
@IBAction func updateLocation(sender: AnyObject) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}