【发布时间】:2015-03-18 22:43:43
【问题描述】:
我想获取当前设备位置并将地图缩放到该坐标。
我也不想在缩放到用户位置后停止位置管理器,以防止在用户移动时更改地图可见区域。
...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();
}
此代码的问题是此代码将地图视图移动到海洋并且坐标有时无效(另一个大陆)。
当我停止位置管理器时,地图视图停留在海洋中:-/
制作我想要的东西的正确方法是什么?
【问题讨论】:
-
你应该总是省略 self.如果需要,Xcode 会要求您添加它。
-
这里有你可以查看的链接> stackoverflow.com/questions/22292835/…
标签: swift ios7 ios8 mkmapview core-location