//下面是對這個問題的一些詳細信息=嘗試啓動MapKit位置更新,而不提示進行位置信息授權。必須首先調用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]。我試着去地圖上顯示我的當前位置,但是當我在模擬器中運行我的代碼,這是行不通的
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet var myMap : MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
myMap.showsUserLocation = true }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("Errors: " + error.localizedDescription)
}
@IBAction func satelliteView(){
myMap.mapType = MKMapType.Satellite
}
@IBAction func normalView(){
myMap.mapType = MKMapType.Standard
}
@IBAction func pin(sender: UILongPressGestureRecognizer) {
let location = sender.locationInView(self.myMap)
let lCoord = self.myMap.convertPoint(location, toCoordinateFromView: self.myMap)
let anno = MKPointAnnotation()
anno.coordinate = lCoord
anno.title = "store"
anno.subtitle = "loctaion of Store"
self.myMap.removeAnnotations(myMap.annotations)
self.myMap.addAnnotation(anno)
}
}
請解釋一下你的沒有按」是什麼意思。牛逼的工作 - 否則很難知道如何幫助你 – Feldur
當我欠幅脈衝模擬器它只是顯示一個世界地圖,並在所有 –
沒有指出我的當前位置你選擇忽略的位置代表向您發送等。比打印出來,所以這就是爲什麼你的當前位置不露面。什麼是啓動的時候'pin'功能呢? – Feldur