0
0

More than 5 years have passed since last update.

mapViewに長押しでピンを追加する方法

Posted at

mapViewに長押しでピンを追加する方法

storyboardにmapviewを追加するのは省略

func longPressed(sender: UILongPressGestureRecognizer) {
    //長押しした地図上の座標
    let tappedLocation = sender.locationInView(mapView)
    let tappedPoint = mapView.convertPoint(tappedLocation, toCoordinateFromView: mapView)
    //ピンの生成
    let pin = MKPointAnnotation()
    //ピンを置く場所を指定
    pin.coordinate = tappedPoint
    //ピンのタイトル
    pin.title = "タイトル"
    //ピンのサブタイトル
    pin.subtitle = "2016/7/1"
    //ピンをMapViewの上に追加
    self.mapView.addAnnotation(pin)
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0