丢弃引脚当前位置xCode6 Swift

时间:2015-03-04 10:57:14

标签: ios xcode swift xcode6 cllocationmanager

我是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

} 
}

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

这可能对你有所帮助。

MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = loc.coordinate;
point.title = @"Where am I?";
point.subtitle = @"I'm here!!!";

[self.mapView addAnnotation:point];