我是Swift的新手。我正在按照教程在地图上进行注释。我成功地制作了一个注释,就教程而言...我一直在寻找如何使用Swift进行多个注释并且无法找到它。
如何在地图上制作多个注释? 感谢。
以下是来自viewcontroller.swift的代码:
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
//setting the map region
let latitude: CLLocationDegrees = 33.606800
let longitude: CLLocationDegrees = -111.845360
let latDelta: CLLocationDegrees = 0.01
let lonDelta: CLLocationDegrees = 0.01
let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
map.setRegion(region, animated: true)
//map annotation
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "Taliesin West"
annotation.subtitle = "Design"
map.addAnnotation(annotation)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:0)
只需像示例那样创建另一个注释并调用
map.addAnnotation(another)