2016-02-29 73 views
0

我是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. 
    } 


} 
+0

认为这是一个起点。 [添加多个注释](http://stackoverflow.com/questions/32938044/mapkit-adding-multiple-annotations-from-core-data)你也可以查看这个[Tutorial](http://rshankar.com /如何到附加的MapView的注释和拖动,折线式 - 斯威夫特/)。这也是一分钟搜索找到这些。请尝试一下,然后显示您的代码不起作用。 – MwcsMac

+0

谢谢你的回应。这看起来与我所拥有的完全不同。 –

+0

我应该将其粘贴到我拥有的或者为每个注释执行此操作或将其添加到我目前拥有的代码中?我打算做的下一个注释是:Fallingwater纬度39.906299经度-79.467794 –

回答

0

只需创建类似实例的另一注解并没有做,并呼吁

map.addAnnotation(another) 
+0

感谢您的回复。我打算做的下一个注释是:Fallingwater纬度39.906299经度-79.467794。我目前不在电脑前。我挣扎的一部分是第二个位置的纬度和经度。这是第二个注释应该看起来如何?让另一= MKPointAnnotation() another.coordinate = locationTwo =(39.906299,-79.467794) another.title = “流水” another.subtitle = “设计” map.addAnnotation(另一个) –