Tôi muốn hiển thị vị trí của người dùng và khu vực xung quanh, nhưng tôi cũng muốn cho phép người dùng xoay quanh khu vực. Ngay bây giờ nếu tôi cố gắng di chuyển đến một nơi khác trên bản đồ, nó sẽ tự động đưa tôi trở lại vùng cơ sở với người dùng ở trung tâm. Làm cách nào để ngăn chặn điều này? Tôi muốn hiển thị chế độ xem ban đầu với người dùng ở giữa, nhưng tôi cũng muốn có thể cuộn xung quanh. Cảm ơn trước các bạn rất hữu ích!Swift Mapkit - Di chuyển ra khỏi vị trí người dùng
nhập khẩu UIKit nhập khẩu MapKit nhập khẩu CoreLocation
lớp ViewControllerMain: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
var locationManager:CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.startUpdatingLocation()
mapView.showsUserLocation = true
mapView.delegate = self
let longPress = UILongPressGestureRecognizer(target: self, action: "action:")
longPress.minimumPressDuration = 1.0
mapView.addGestureRecognizer(longPress)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let regionToZoom = MKCoordinateRegionMake(manager.location.coordinate, MKCoordinateSpanMake(0.01, 0.01))
mapView.setRegion(regionToZoom, animated: true)
}
bạn có thể cung cấp một ví dụ về một trong hai lựa chọn? Tôi hiểu khái niệm. Cú pháp tôi đang làm gì đó sai – Murph