9
MapKitの使い方を理解しようとする新しいコーダー。目標は、ユーザーがアドレスを使用してピンを追加できるマップを作成することです。しかし、私は現在の段階ですが、ピンをマップに追加する方法を理解することができません。MapKit - Swift 3.0を使用してマップにピンを追加する
ピンをマップに追加するにはどうすればよいですか?私は今までの注釈の使い方を理解するのに苦労してきました。
これは私が助けと方向性を望んでいることです。ありがとう!
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{
@IBOutlet weak var bigMap: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.bigMap.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02))
self.bigMap.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Errors " + error.localizedDescription)
}
}
ミスラフ、助けてくれてありがとう!これはまさに私が必要としていたものです。 – roguephillips
私はurコードを使用して注釈を追加しましたが、注釈は地図に表示されません??? –
これのために表示されません。https://stackoverflow.com/questions/39469529/swift-adding-annotations-on-map – Cesare