0
我在我的項目開始時在用戶位置上工作過mapview,但現在它不會在啓動時放大用戶。任何想法如何解決這個問題?代碼我使用:Swift User Location Issue
在類
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
var Locationmanager = CLLocationManager()
在viewDidLoad中
self.Locationmanager.delegate = self
self.Locationmanager.desiredAccuracy = kCLLocationAccuracyBest
self.Locationmanager.requestWhenInUseAuthorization()
self.Locationmanager.startUpdatingLocation()
self.Mapview.showsUserLocation = true
Mapview.setCenterCoordinate(Mapview.userLocation.coordinate, animated: true)
在功能
func locationManager(manager: CLLocationManager, didUpdateLocations locations:[MKUserLocation]) {
let latitude = Locationmanager.location?.coordinate.latitude
let longitude = Locationmanager.location?.coordinate.longitude
let center = CLLocationCoordinate2D (latitude: latitude!, longitude: longitude!)
let region = MKCoordinateRegion (center: center, span: MKCoordinateSpan (latitudeDelta: 0.02, longitudeDelta: 0.02))
self.Mapview.setRegion(region, animated: true)
self.Locationmanager.stopUpdatingLocation()
而在info.plist中
NSLocationWhenInUseUsageDescription
嗯,我需要問的用戶位置的權限..將嘗試並刪除,看看發生了什麼 – Adam
仍然沒有得到在啓動用戶位置的變焦.. – Adam
不能解決它..任何其他用於查找用戶位置的代碼? – Adam