【发布时间】:2018-04-19 16:16:21
【问题描述】:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mapKit: MKMapView!
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let span: MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
let myLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region: MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
mapKit.setRegion(region, animated: true)
self.mapKit.showsUserLocation = true
}
override func viewDidLoad() {
super.viewDidLoad()
let manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
}
}
这是我的源代码。我正在使用 Xcode 9 和 swift 4.0
当我构建并运行时,调试区域会打印此“无法从角落 4 插入法律归属”,并使用 GPS 警报自动关闭。所以我不能接受使用 GPS 允许。
我也是这样完成info.plist设置的。
隐私 - 始终定位和使用时使用说明 隐私 - 始终位置 使用说明 隐私 - 使用时的位置使用说明。
有什么问题?
【问题讨论】:
标签: ios swift xcode mapkit cllocationmanager