我是iOS開發新手,需要在iOS地圖中實現可拖動的註釋。我的代碼是below.whater曾經給我做,我不能得到一個可拖動標註任何人都可以使用之後的註解,我需要獲得位置的地址,幫助其中銷指向iOS Mapkit註解不可拖動
RegistrationViewController.swift
class RegistrationViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,MKMapViewDelegate{
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
var centerLocation = CLLocationCoordinate2DMake(12.964370125970357, 77.59643554937497)
var mapspan = MKCoordinateSpanMake(0.01, 0.01)
var mapregion = MKCoordinateRegionMake(centerLocation, mapspan)
self.mapView.setRegion(mapregion, animated: true)
let pin = pinAnnotation(title:"hello",subtitle:"how are you",coordinate:centerLocation)
mapView.addAnnotation(pin)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKPointAnnotation {
let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin")
pinAnnotationView.pinColor = .purple
pinAnnotationView.isDraggable = true
pinAnnotationView.canShowCallout = true
pinAnnotationView.animatesDrop = true
return pinAnnotationView
}
return nil
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, didChange newState: MKAnnotationViewDragState, fromOldState oldState: MKAnnotationViewDragState) {
switch newState {
case .starting:
view.dragState = .dragging
case .ending, .canceling:
view.dragState = .none
default: break
}
}
pinAnnotation.swift
import MapKit
class pinAnnotation:NSObject,MKAnnotation {
var title:String?
var subtitle: String?
var coordinate: CLLocationCoordinate2D
init(title:String,subtitle:String,coordinate:CLLocationCoordinate2D) {
self.title = title
self.subtitle = subtitle
self.coordinate = coordinate
}
}
其工作的兄弟感謝! –
兄弟你能告訴我如何獲得標記指向的位置地址現在 –
檢查更新的答案。 –