# How to change a pin color in swift 3 using map kit

**URL:** <https://forums.kodeco.com/t/how-to-change-a-pin-color-in-swift-3-using-map-kit/25454>\
**Category:** Swift\
**Created:** [January 22, 2017, 12:01am UTC](https://forums.kodeco.com/t/how-to-change-a-pin-color-in-swift-3-using-map-kit/25454 "2017-01-22T00:01:11Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![zalubski](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/zalubski/32/81494_2.png) [@zalubski](https://forums.kodeco.com/u/zalubski)\
**Post date:** [January 23, 2017, 5:14am UTC](https://forums.kodeco.com/t/how-to-change-a-pin-color-in-swift-3-using-map-kit/25454/3 "2017-01-23T05:14:48Z")

</div>

This is what i have now still not working. Notice the comment lines for color.

```
  import MapKit
   import UIKit

   class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
//color
 let annotation = ColorPointAnnotation(pinColor: UIColor.blueColor())

override func viewDidLoad() {
	super.viewDidLoad()

	let london = Capital(title: "London", coordinate: CLLocationCoordinate2D(latitude: 51.507222, longitude: -0.1275), info: "Home to the 2012 Summer Olympics.")
	let oslo = Capital(title: "Oslo", coordinate: CLLocationCoordinate2D(latitude: 59.95, longitude: 10.75), info: "Founded over a thousand years ago.")
    
    
	
	 mapView.addAnnotations([london, oslo])
    
}

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
	// 1
	let identifier = "Capital"

	// 2
	if annotation is Capital {
       

		// 3
        
		var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

		if annotationView == nil {
			//4
			annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
			annotationView!.canShowCallout = true
            //color
            let colorPointAnnotation = annotation as! ColorPointAnnotation
            annotationView?.pinTintColor = colorPointAnnotation.pinColor

			// 5
			let btn = UIButton(type: .detailDisclosure)
			annotationView!.rightCalloutAccessoryView = btn
		} else {
			// 6
			annotationView!.annotation = annotation
            
		}

		return annotationView
	}

	// 7
	return nil
    
}

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
	let capital = view.annotation as! Capital
	let placeName = capital.title
	let placeInfo = capital.info
    

	let ac = UIAlertController(title: placeName, message: placeInfo, preferredStyle: .alert)
	ac.addAction(UIAlertAction(title: "OK", style: .default))
	present(ac, animated: true)
}
     }

```

---

_[View the full topic](https://forums.kodeco.com/t/how-to-change-a-pin-color-in-swift-3-using-map-kit/25454)._
