当我使用让viewRegion = MKCoordinateRegionMakeWithDistance((用户位置?.coordinate)!600,600),这是罚款,但显然雨燕现在换成这个与
让viewRegion = MKCoordinateRegion(中心:(用户位置.coordinate)!latitudinalMeters:600,longitudinalMeters:600)
我的位置不再在地图上出现了,地图显示的右侧区域。这里是我的代码。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
let userLocation = locations.last
let viewRegion = MKCoordinateRegion(center: (userLocation?.coordinate)!, latitudinalMeters: 600, longitudinalMeters: 600)
self.map.setRegion(viewRegion, animated: true)
}
首先希望你没有忘记从CLLocationManagerDelegate
和MKMapViewDelegate
扩展您的视图 - 控制。
您可以直接从locationManager
可变private let locationManager: CLLocationManager = CLLocationManager()
从任何地方通过调用访问用户位置在您的类
userLocation = self.locationManager.location
也不要忘记您的视图控制器委托给位置管理和MapView的:
locationManager.delegate = self
mapView.delegate = self