我对xCode6相当陌生,很难让我的应用程序在我当前的位置设置一个引脚。我想要做的就是允许用户用一个引脚标记一个点,然后捕获那个坐标的长和拉特-最好是在println()中。
我已经搜索了一段时间,但没有发现任何人解释这一点在斯威夫特或xcode6。由于我不知道如何翻译,无论用什么旧的语言来快速,我想我应该在这里张贴这个问题。
我有下面的代码,请帮帮我。
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet var myMap : MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.locationManager.requestWhenInUseAuthorization()
// 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.
}
@IBAction func satelliteView(){
myMap.mapType = MKMapType.Satellite
}
@IBAction func normalView(){
myMap.mapType = MKMapType.Standard
}
}发布于 2015-03-04 11:12:51
若要将注释放置在当前位置的相同坐标上,可以使用:
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: self.myMap.userLocation.coordinate.latitude, longitude: self.myMap.userLocation.coordinate.longitude)
self.myMap.addAnnotation(annotation)发布于 2015-03-04 11:57:59
这可能对你有帮助。
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = loc.coordinate;
point.title = @"Where am I?";
point.subtitle = @"I'm here!!!";
[self.mapView addAnnotation:point];https://stackoverflow.com/questions/28852683
复制相似问题