Button Swift 3-如何在此案例中在每个注释中添加按钮
我试图找到很多关于在注释中添加按钮的教程。 但它只适用于他们的案例或新项目。我不知道如何将它应用到我的案例中。我真搞不懂如何开展我的毕业设计 导入UIKit 导入地图套件 导入核心定位 类ViewController:UIViewController、CLLocationManagerDelegate、MKMapViewDelegate{Button Swift 3-如何在此案例中在每个注释中添加按钮,button,swift3,annotations,mkmapview,Button,Swift3,Annotations,Mkmapview,我试图找到很多关于在注释中添加按钮的教程。 但它只适用于他们的案例或新项目。我不知道如何将它应用到我的案例中。我真搞不懂如何开展我的毕业设计 导入UIKit 导入地图套件 导入核心定位 类ViewController:UIViewController、CLLocationManagerDelegate、MKMapViewDelegate{ @IBOutlet weak var mapView: MKMapView! //my location let manager = CLLocation
@IBOutlet weak var mapView: MKMapView!
//my location
let manager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
mapView.setRegion(region, animated: true)
print(location.altitude)
print(location.speed)
self.mapView.showsUserLocation = true
}
override func viewDidLoad() {
super.viewDidLoad()
//my location
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
let distanceSpan:CLLocationDegrees = 250
//KT1 Annotation
let KT1Location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.310491, 114.227998)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(KT1Location, distanceSpan, distanceSpan),animated: true)
let KT1CSClassPin = KT1Annotation(title: "觀塘工業中心第一期", subtitle: "觀塘道 472-484號", coordinate: KT1Location)
mapView.addAnnotation( KT1CSClassPin )
//KT2 Annotation
let KT2Location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.310724, 114.227626)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(KT2Location, distanceSpan, distanceSpan),animated: true)
let KT2CSClassPin = KT2Annotation(title: "觀塘工業中心第二期", subtitle: "觀塘道 460-470號", coordinate: KT2Location)
mapView.addAnnotation( KT2CSClassPin )
//KT3 Annotation
let KT3Location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.310957, 114.227255)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(KT3Location, distanceSpan, distanceSpan),animated: true)
let KT3CSClassPin = KT3Annotation(title: "觀塘工業中心第三期", subtitle: "觀塘道 448-458號", coordinate: KT3Location)
mapView.addAnnotation( KT3CSClassPin )
//KT4 Annotation
let KT4Location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.311364, 114.226883)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(KT4Location, distanceSpan, distanceSpan),animated: true)
let KT4CSClassPin = KT4Annotation(title: "觀塘工業中心第四期", subtitle: "觀塘道 436-446號", coordinate: KT4Location)
mapView.addAnnotation( KT4CSClassPin )
//CP1 Annotation
let CP1Location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.310459, 114.22516470000005)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(CP1Location, distanceSpan, distanceSpan),animated: true)
let CP1CSClassPin = CP1Annotation(title: "駱駝漆大廈第1座", subtitle: "開源道 62號", coordinate: CP1Location)
mapView.addAnnotation( CP1CSClassPin )
//CP3 Annotation
let CP3Location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.310125, 114.225072)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(CP3Location, distanceSpan, distanceSpan),animated: true)
let CP3CSClassPin = CP3Annotation(title: "駱駝漆大廈第3座", subtitle: "開源道 60號", coordinate: CP3Location)
mapView.addAnnotation( CP3CSClassPin )
}
我认为你应该看看苹果的“MapCallout”例子,关于如何定制插针和插针气泡。链接:这是一个swift例子吗?它和Objective-C程序一样。是的,它是Objective-C。但是,如果你能受到启发完成任务,你可以将它转换为swift,或者问另一个问题。