2015-03-18 51 views
0

我想獲取當前設備位置並將地圖縮放到該座標。
我也不想在縮放到用戶位置後停止位置管理器,以防止用戶移動時更改地圖可見區域。
如何獲得準確的用戶座標並停止位置管理器

...viewDidLoad...{ 
self.locationManager = CLLocationManager(); 
     self.locationManager.delegate = self; 
     self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
     self.mapView.showsUserLocation = true; 
     self.locationManager.startUpdatingLocation(); 
} 

func locationManager(manager:CLLocationManager, didUpdateLocations locations:[AnyObject]){ 
var newRegion = MKCoordinateRegion(center: self.mapView.userLocation.coordinate, span: MKCoordinateSpanMake(0.014, 0.014)); 
      self.mapView.setRegion(newRegion, animated: true); 
      self.locationManager.stopUpdatingLocation(); 
} 

問題的這個代碼是此代碼移動地圖視圖海洋和座標是無效有時(另一個大陸)。
而當我停止位置管理器地圖視圖留在海洋中: -/
什麼是使我想要的正確方法?

+0

你應該總是忽略自己。如果需要Xcode會要求你添加它。 – 2015-03-18 23:07:27

+0

您可以查看 > https://stackoverflow.com/questions/22292835/how-to-stop-multiple-times-method-calling-of-didupdatelocations-in-ios/46580983#46580983 – 2017-10-05 08:25:52

回答