我是Swift的新手。我正在按照教程在地圖上進行註釋。我成功地做了一個註釋,那就教程去...我一直在四處尋找試圖找到如何使用Swift進行多個註釋,並找不到它。如何在Swift中使用GPS座標在地圖上添加多個註釋?
如何在地圖上製作多個註釋? 謝謝。
下面是從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.
}
}
認爲這是一個起點。 [添加多個註釋](http://stackoverflow.com/questions/32938044/mapkit-adding-multiple-annotations-from-core-data)你也可以查看這個[Tutorial](http://rshankar.com /如何到附加的MapView的註釋和拖動,折線式 - 斯威夫特/)。這也是一分鐘搜索找到這些。請嘗試一下,然後顯示您的代碼不起作用。 – MwcsMac
謝謝你的迴應。這看起來與我所擁有的完全不同。 –
我應該將其粘貼到我擁有的或者爲每個註釋執行此操作或將其添加到我目前擁有的代碼中?我打算做的下一個註釋是:Fallingwater緯度39.906299經度-79.467794 –