簡體   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