Skip to main content
 首页 » 操作系统

ios之删除当前位置 xCode6 Swift

2024年01月01日50youxin

我是 xCode6 的新手,很难让我的应用程序在我的当前位置上放置图钉。我想做的就是允许用户用大头针标记一个点,然后捕获该坐标的经度和纬度——最好是在 println() 中。

我搜索了一下,但没有找到任何人在 swift 或 xcode6 中对此进行解释。由于我不知道如何将过去使用的任何旧语言翻译成 swift,所以我想我会在此处发布问题。

我有以下代码,请帮帮我。


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 
 
}  
} 

请您参考如下方法:

要在您当前位置的相同坐标处放置注释,您可以使用:

let annotation = MKPointAnnotation() 
annotation.coordinate = CLLocationCoordinate2D(latitude: self.myMap.userLocation.coordinate.latitude, longitude: self.myMap.userLocation.coordinate.longitude) 
self.myMap.addAnnotation(annotation)