gpt4 book ai didi

ios - 如何通过 Swift 使用 GPS 坐标在 map 上添加多个注释?

转载 作者:行者123 更新时间:2023-11-30 13:39:58 24 4
gpt4 key购买 nike

我是 Swift 新手。我正在按照教程在 map 上进行注释。我成功地做了一个注释,这就是本教程的内容...我一直在寻找如何使用 Swift 进行多个注释,但找不到它。

如何在 map 上进行多个注释?谢谢。

这是我来自 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)

关于ios - 如何通过 Swift 使用 GPS 坐标在 map 上添加多个注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35690679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com