【发布时间】:2015-07-12 01:11:37
【问题描述】:
我想要做的是有一个用户可以点击的按钮来保存他们当前的位置。然后,在地图上,保存位置的位置会出现一个图钉。我该怎么做呢?我已经搜索了一些示例代码,但我找不到任何工作或在 Swift 中。
我有它,所以用户也可以随时看到他们在哪里。 Bellow 是我目前拥有的代码。
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)
}
}
我会在这段代码中添加什么来实现我在第一段中描述的目标?
【问题讨论】:
标签: swift gps xcode6 mapkit core-location