2015-03-18 45 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

回答