使用 MapKit 在地图上显示带有图钉的自定义位置 (Swift)

Show custom location with pin on Map with MapKit (Swift)

我正在尝试在我的应用程序中创建一个显示餐厅位置的视图。当用户进入视图时,它会显示这样的东西

而是用大头针和放大的视图显示餐厅的位置。我是 MapKit 的新手,一直没有取得任何进展。

这就是我的观点。

这就是我的视图控制器的组成部分。

import UIKit
import MapKit

class FD1ViewController: UIViewController {


@IBOutlet weak var mapView: MKMapView!
private let locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



}
import UIKit
import MapKit

class FD1ViewController: UIViewController {

   @IBOutlet weak var mapView: MKMapView!

   override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)

      //Create the pin location of your restaurant(you need the GPS coordinates for this)
      let restaurantLocation = CLLocationCoordinate2D(latitude: 111.0, longitude: 111.0)

      //Center the map on the place location
      mapView.setCenter(restaurantLocation, animated: true)
   }

}

这应该可以做到。希望对您有所帮助!