0
私が持っているものは、現在のユーザーの場所を見つけてその現在の場所にピンを配置する単純なマップレイアウトです。私はコードが正しいと思うが、自分の位置を動かすとピンが見えない。注釈を地図に表示できないのはなぜですか?
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.
}
}すべての