【发布时间】:2015-11-17 21:59:42
【问题描述】:
我可以使用“第一个”按钮在 MapView 上添加注释,但我想添加一个新选项,该选项可以使用“第二个”按钮删除注释。添加注释没有问题,但我无法从地图视图中删除它。有人可以帮我吗?
这是我的代码:
class ViewController: UIViewController {
@IBOutlet weak var mapViewOutlet: MKMapView!
var lm = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.lm.requestAlwaysAuthorization()
mapViewOutlet.showsUserLocation = true
mapViewOutlet.userTrackingMode = MKUserTrackingMode.Follow
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// HERE IS FUNCTION ADDANNOTATION
@IBAction func tagMyCar(sender: UIButton) {
let coordinate = lm.location?.coordinate
let CarCoordinates = CarAdnotaion(coordinate: coordinate!)
mapViewOutlet.addAnnotation(CarCoordinates)
let region = CLCircularRegion(center: coordinate!, radius: 5, identifier: "My Car")
region.notifyOnEntry = true
region.notifyOnExit = true
lm.startMonitoringForRegion(region)
}
// HERE IS FUNCTION REMOVEANNOTATION
@IBAction func removeAnnotationfromMap(sender: AnyObject) {
let region = CLCircularRegion(center: (lm.location?.coordinate)!, radius: 5, identifier: "Mój samochód")
self.mapViewOutlet.removeAnnotation(CarAdnotaion(coordinate: (lm.location?.coordinate)!))
lm.stopMonitoringForRegion(region)
}
}
【问题讨论】:
标签: ios iphone swift mapkit swift2