【发布时间】:2015-07-13 02:59:46
【问题描述】:
所以我正在创建一个应用程序,当单击按钮时,用户当前位置用于在 Apples mapkit 上创建注释。除了将按钮链接到将创建注释并在地图上显示注释的代码之外,我一切正常。贝娄是我到目前为止的代码:
import UIKit
import CoreLocation
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
@IBOutlet var Map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
println("Updating Location \(newLocation.coordinate.latitude) , \(newLocation.coordinate.longitude) ")
let span = MKCoordinateSpanMake(0.0009, 0.0009)
let region = MKCoordinateRegion(center: newLocation.coordinate, span: span)
Map.setRegion(region, animated: false)
}
}
如您所见,我拥有它,因此它不断向用户显示他们在哪里。我想要这个,但我也希望用户能够创建注释。
我的问题是我需要什么代码来创建注释以及它在哪里?我对编程还很陌生,所以我对所有的代码术语并不完全全面,所以如果你愿意的话(请为我做些蠢事)。此外,当用户单击添加注释的按钮时,需要删除最后一个注释。我该怎么做?我在 Xcode 中使用 Swift。
【问题讨论】:
标签: ios swift gps annotations mapkit