繁体   English   中英

如何在Swift中使用GPS坐标在地图上添加多个注释?

[英]How can I add multiple annotations on a map using GPS coordinates with Swift?

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


}

像示例一样创建另一个注释并调用

map.addAnnotation(another)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM