MKMarkerAnnotationView
も MKPointAnnotation
で緯度経度を指定します。
例:viewDidLoad
などで
let coordinate = CLLocationCoordinate2DMake(37.331652997806785, -122.03072304117417)
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotation.title = "title"
annotation.subtitle = "subtitle"
self.mapView.addAnnotation(annotation)
そして mapView:viewFor
で次のように実装します。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKMarkerAnnotationView
if pinView == nil {
pinView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
}
else {
pinView?.annotation = annotation
}
return pinView
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/28 14:34
2018/05/28 23:41
2018/05/31 01:19