繁体   English   中英

丢弃引脚当前位置xCode6 Swift

[英]Dropping pin current location xCode6 Swift

我是xCode6的新手,我很难让我的应用程序在当前位置放置一个引脚。 我想要做的就是让用户用一个引脚标记一个点,然后捕获该坐标的长度和纬度 - 最好是在println()中。

我已经搜索了一下,但没有找到任何人在swift或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

} 
}

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

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

这可能会对你有所帮助。

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

[self.mapView addAnnotation:point];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM