【问题标题】:Show custom location with pin on Map with MapKit (Swift)使用 MapKit (Swift) 在地图上显示带有引脚的自定义位置
【发布时间】:2019-02-03 04:32:07
【问题描述】:

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

而是用大头针和更放大的视图显示餐厅的位置。我是 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.
}



}

【问题讨论】:

标签: swift annotations location mkmapview


【解决方案1】:
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)
   }

}

应该这样做。希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多