我想顯示用戶位置和周圍區域,但我也希望允許用戶在該區域周圍平移。現在,如果我嘗試在地圖上的其他地方滾動,它會自動將我帶回中心用戶所在的基本區域。我該如何阻止?我想在中心顯示用戶的初始視圖,但我也希望能夠滾動。在此先感謝你們,如此有幫助!Swift Mapkit - 遠離用戶位置
進口的UIKit 進口MapKit 進口CoreLocation
類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)
}
你能提供任一選項的例子嗎?我理解這個概念。從句法上來說,我正在做一些不正確的事情 – Murph 2015-02-17 15:37:49