2016-09-20 52 views
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 

回答

0

如果您的目標是使地圖視圖顯示用戶的位置,則無需任何指示即可告知位置管理員執行任何操作。擺脫所有的代碼 - 它實際上在這裏對你造成傷害。只需將地圖視圖的userTrackingMode設置爲.follow並退後即可。

+0

嗯,我需要問的用戶位置的權限..將嘗試並刪除,看看發生了什麼 – Adam

+0

仍然沒有得到在啓動用戶位置的變焦.. – Adam

+0

不能解決它..任何其他用於查找用戶位置的代碼? – Adam