我到目前为止所做的是创建一个地图。然后显示用户位置和中心,它使行驶(汽车等)用注释针创建长按手势识别器
时地图居中但现在我想补充一个长按手势,这样如果用户不输入引脚将被丢弃。我一直在努力处理教程和模拟器崩溃。
我怎么想补充longPressGesturerecognizer
,使其滴针在我的mapView
。
这里是我的代码 -
import UIKit
import MapKit
import CoreLocation
class Page2: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate{
@IBOutlet var mapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
//blue dot on the map
self.mapView.showsUserLocation = true
//tracking mode on
self.mapView.userTrackingMode = .follow
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// location Manager Delegate center user on map
private func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: (location?.coordinate.longitude)!)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)) //zoom on map
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
// print errors
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error){
print("Errors: " + error.localizedDescription)
}
}
感谢我似乎在这条线被歌厅此错误 让longPressGesture = UILongPressGestureRecognizer(目标:自我,动作:#selector(addAnnotationOnLongPress(手势:))) 使用局部变量addAnnotationOnLongPress的”(手势:)”其声明 – sabrefm1
之前没有后顾之忧我sorrted – sabrefm1
唯一的事情就是现在看到的是,坐标记录在输出,但@ sabrefm1你有没有加入'addAnnotation'的代码它不是丢弃任何引脚 – sabrefm1